Deprecated SetItemImage with 2 image ids
[wxWidgets.git] / src / msw / listctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/listctrl.cpp
3 // Purpose: wxListCtrl
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "listctrl.h"
22 #pragma implementation "listctrlbase.h"
23 #endif
24
25 // For compilers that support precompilation, includes "wx.h".
26 #include "wx/wxprec.h"
27
28 #ifdef __BORLANDC__
29 #pragma hdrstop
30 #endif
31
32 #if wxUSE_LISTCTRL && defined(__WIN95__)
33
34 #ifndef WX_PRECOMP
35 #include "wx/app.h"
36 #include "wx/intl.h"
37 #include "wx/log.h"
38 #include "wx/settings.h"
39 #endif
40
41 #include "wx/textctrl.h"
42 #include "wx/imaglist.h"
43 #include "wx/listctrl.h"
44 #include "wx/dcclient.h"
45
46 #include "wx/msw/private.h"
47
48 #if defined(__WXWINCE__) && !defined(__HANDHELDPC__)
49 #include <ole2.h>
50 #include <shellapi.h>
51 #if _WIN32_WCE < 400
52 #include <aygshell.h>
53 #endif
54 #endif
55
56 // include <commctrl.h> "properly"
57 #include "wx/msw/wrapcctl.h"
58
59 // ----------------------------------------------------------------------------
60 // private functions
61 // ----------------------------------------------------------------------------
62
63 // convert our state and mask flags to LV_ITEM constants
64 static void wxConvertToMSWFlags(long state, long mask, LV_ITEM& lvItem);
65
66 // convert wxListItem to LV_ITEM
67 static void wxConvertToMSWListItem(const wxListCtrl *ctrl,
68 const wxListItem& info, LV_ITEM& lvItem);
69
70 // convert LV_ITEM to wxListItem
71 static void wxConvertFromMSWListItem(HWND hwndListCtrl,
72 wxListItem& info,
73 /* const */ LV_ITEM& lvItem);
74
75 // convert our wxListItem to LV_COLUMN
76 static void wxConvertToMSWListCol(int col, const wxListItem& item,
77 LV_COLUMN& lvCol);
78
79 // ----------------------------------------------------------------------------
80 // private helper classes
81 // ----------------------------------------------------------------------------
82
83 // We have to handle both fooW and fooA notifications in several cases
84 // because of broken comctl32.dll and/or unicows.dll. This class is used to
85 // convert LV_ITEMA and LV_ITEMW to LV_ITEM (which is either LV_ITEMA or
86 // LV_ITEMW depending on wxUSE_UNICODE setting), so that it can be processed
87 // by wxConvertToMSWListItem().
88 #if wxUSE_UNICODE
89 #define LV_ITEM_NATIVE LV_ITEMW
90 #define LV_ITEM_OTHER LV_ITEMA
91
92 #define LV_CONV_TO_WX cMB2WX
93 #define LV_CONV_BUF wxMB2WXbuf
94 #else // ANSI
95 #define LV_ITEM_NATIVE LV_ITEMA
96 #define LV_ITEM_OTHER LV_ITEMW
97
98 #define LV_CONV_TO_WX cWC2WX
99 #define LV_CONV_BUF wxWC2WXbuf
100 #endif // Unicode/ANSI
101
102 class wxLV_ITEM
103 {
104 public:
105 // default ctor, use Init() later
106 wxLV_ITEM() { m_buf = NULL; m_pItem = NULL; }
107
108 // init without conversion
109 void Init(LV_ITEM_NATIVE& item)
110 {
111 wxASSERT_MSG( !m_pItem, _T("Init() called twice?") );
112
113 m_pItem = &item;
114 }
115
116 // init with conversion
117 void Init(LV_ITEM_OTHER& item)
118 {
119 // avoid unnecessary dynamic memory allocation, jjust make m_pItem
120 // point to our own m_item
121
122 // memcpy() can't work if the struct sizes are different
123 wxCOMPILE_TIME_ASSERT( sizeof(LV_ITEM_OTHER) == sizeof(LV_ITEM_NATIVE),
124 CodeCantWorkIfDiffSizes);
125
126 memcpy(&m_item, &item, sizeof(LV_ITEM_NATIVE));
127
128 // convert text from ANSI to Unicod if necessary
129 if ( (item.mask & LVIF_TEXT) && item.pszText )
130 {
131 m_buf = new LV_CONV_BUF(wxConvLocal.LV_CONV_TO_WX(item.pszText));
132 m_item.pszText = (wxChar *)m_buf->data();
133 }
134 }
135
136 // ctor without conversion
137 wxLV_ITEM(LV_ITEM_NATIVE& item) : m_buf(NULL), m_pItem(&item) { }
138
139 // ctor with conversion
140 wxLV_ITEM(LV_ITEM_OTHER& item) : m_buf(NULL)
141 {
142 Init(item);
143 }
144
145 ~wxLV_ITEM() { delete m_buf; }
146
147 // conversion to the real LV_ITEM
148 operator LV_ITEM_NATIVE&() const { return *m_pItem; }
149
150 private:
151 LV_CONV_BUF *m_buf;
152
153 LV_ITEM_NATIVE *m_pItem;
154 LV_ITEM_NATIVE m_item;
155
156 DECLARE_NO_COPY_CLASS(wxLV_ITEM)
157 };
158
159 ///////////////////////////////////////////////////////
160 // Problem:
161 // The MSW version had problems with SetTextColour() et
162 // al as the wxListItemAttr's were stored keyed on the
163 // item index. If a item was inserted anywhere but the end
164 // of the list the the text attributes (colour etc) for
165 // the following items were out of sync.
166 //
167 // Solution:
168 // Under MSW the only way to associate data with a List
169 // item independant of its position in the list is to
170 // store a pointer to it in its lParam attribute. However
171 // user programs are already using this (via the
172 // SetItemData() GetItemData() calls).
173 //
174 // However what we can do is store a pointer to a
175 // structure which contains the attributes we want *and*
176 // a lParam for the users data, e.g.
177 //
178 // class wxListItemInternalData
179 // {
180 // public:
181 // wxListItemAttr *attr;
182 // long lParam; // user data
183 // };
184 //
185 // To conserve memory, a wxListItemInternalData is
186 // only allocated for a LV_ITEM if text attributes or
187 // user data(lparam) are being set.
188
189
190 // class wxListItemInternalData
191 class wxListItemInternalData
192 {
193 public:
194 wxListItemAttr *attr;
195 LPARAM lParam; // user data
196
197 wxListItemInternalData() : attr(NULL), lParam(0) {}
198 ~wxListItemInternalData()
199 {
200 if (attr)
201 delete attr;
202 };
203
204 DECLARE_NO_COPY_CLASS(wxListItemInternalData)
205 };
206
207 // Get the internal data structure
208 static wxListItemInternalData *wxGetInternalData(HWND hwnd, long itemId);
209 static wxListItemInternalData *wxGetInternalData(const wxListCtrl *ctl, long itemId);
210 static wxListItemAttr *wxGetInternalDataAttr(wxListCtrl *ctl, long itemId);
211 static void wxDeleteInternalData(wxListCtrl* ctl, long itemId);
212
213
214 // ----------------------------------------------------------------------------
215 // events
216 // ----------------------------------------------------------------------------
217
218 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG)
219 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG)
220 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT)
221 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT)
222 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM)
223 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS)
224 #if WXWIN_COMPATIBILITY_2_4
225 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO)
226 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO)
227 #endif
228 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED)
229 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED)
230 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN)
231 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM)
232 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK)
233 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK)
234 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG)
235 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING)
236 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG)
237 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK)
238 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK)
239 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED)
240 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED)
241 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT)
242
243 #if wxUSE_EXTENDED_RTTI
244 WX_DEFINE_FLAGS( wxListCtrlStyle )
245
246 wxBEGIN_FLAGS( wxListCtrlStyle )
247 // new style border flags, we put them first to
248 // use them for streaming out
249 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
250 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
251 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
252 wxFLAGS_MEMBER(wxBORDER_RAISED)
253 wxFLAGS_MEMBER(wxBORDER_STATIC)
254 wxFLAGS_MEMBER(wxBORDER_NONE)
255
256 // old style border flags
257 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
258 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
259 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
260 wxFLAGS_MEMBER(wxRAISED_BORDER)
261 wxFLAGS_MEMBER(wxSTATIC_BORDER)
262 wxFLAGS_MEMBER(wxBORDER)
263
264 // standard window styles
265 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
266 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
267 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
268 wxFLAGS_MEMBER(wxWANTS_CHARS)
269 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
270 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
271 wxFLAGS_MEMBER(wxVSCROLL)
272 wxFLAGS_MEMBER(wxHSCROLL)
273
274 wxFLAGS_MEMBER(wxLC_LIST)
275 wxFLAGS_MEMBER(wxLC_REPORT)
276 wxFLAGS_MEMBER(wxLC_ICON)
277 wxFLAGS_MEMBER(wxLC_SMALL_ICON)
278 wxFLAGS_MEMBER(wxLC_ALIGN_TOP)
279 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT)
280 wxFLAGS_MEMBER(wxLC_AUTOARRANGE)
281 wxFLAGS_MEMBER(wxLC_USER_TEXT)
282 wxFLAGS_MEMBER(wxLC_EDIT_LABELS)
283 wxFLAGS_MEMBER(wxLC_NO_HEADER)
284 wxFLAGS_MEMBER(wxLC_SINGLE_SEL)
285 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING)
286 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING)
287 wxFLAGS_MEMBER(wxLC_VIRTUAL)
288
289 wxEND_FLAGS( wxListCtrlStyle )
290
291 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl, wxControl,"wx/listctrl.h")
292
293 wxBEGIN_PROPERTIES_TABLE(wxListCtrl)
294 wxEVENT_PROPERTY( TextUpdated , wxEVT_COMMAND_TEXT_UPDATED , wxCommandEvent )
295
296 wxPROPERTY_FLAGS( WindowStyle , wxListCtrlStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
297 wxEND_PROPERTIES_TABLE()
298
299 wxBEGIN_HANDLERS_TABLE(wxListCtrl)
300 wxEND_HANDLERS_TABLE()
301
302 wxCONSTRUCTOR_5( wxListCtrl , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle )
303
304 /*
305 TODO : Expose more information of a list's layout etc. via appropriate objects (à la NotebookPageInfo)
306 */
307 #else
308 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
309 #endif
310
311 IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl)
312 IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
313
314 IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
315
316 BEGIN_EVENT_TABLE(wxListCtrl, wxControl)
317 EVT_PAINT(wxListCtrl::OnPaint)
318 END_EVENT_TABLE()
319
320 // ============================================================================
321 // implementation
322 // ============================================================================
323
324 // ----------------------------------------------------------------------------
325 // wxListCtrl construction
326 // ----------------------------------------------------------------------------
327
328 void wxListCtrl::Init()
329 {
330 m_imageListNormal = NULL;
331 m_imageListSmall = NULL;
332 m_imageListState = NULL;
333 m_ownsImageListNormal = m_ownsImageListSmall = m_ownsImageListState = false;
334 m_colCount = 0;
335 m_count = 0;
336 m_ignoreChangeMessages = false;
337 m_textCtrl = NULL;
338 m_AnyInternalData = false;
339 m_hasAnyAttr = false;
340 }
341
342 bool wxListCtrl::Create(wxWindow *parent,
343 wxWindowID id,
344 const wxPoint& pos,
345 const wxSize& size,
346 long style,
347 const wxValidator& validator,
348 const wxString& name)
349 {
350 if ( !CreateControl(parent, id, pos, size, style, validator, name) )
351 return false;
352
353 if ( !MSWCreateControl(WC_LISTVIEW, _T(""), pos, size) )
354 return false;
355
356 // explicitly say that we want to use Unicode because otherwise we get ANSI
357 // versions of _some_ messages (notably LVN_GETDISPINFOA) in MSLU build
358 wxSetCCUnicodeFormat(GetHwnd());
359
360 // for comctl32.dll v 4.70+ we want to have this attribute because it's
361 // prettier (and also because wxGTK does it like this)
362 if ( InReportView() && wxTheApp->GetComCtl32Version() >= 470 )
363 {
364 ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE,
365 0, LVS_EX_FULLROWSELECT);
366 }
367
368 return true;
369 }
370
371 WXDWORD wxListCtrl::MSWGetStyle(long style, WXDWORD *exstyle) const
372 {
373 WXDWORD wstyle = wxControl::MSWGetStyle(style, exstyle);
374
375 wstyle |= LVS_SHAREIMAGELISTS | LVS_SHOWSELALWAYS;
376
377 #ifdef __WXDEBUG__
378 size_t nModes = 0;
379
380 #define MAP_MODE_STYLE(wx, ms) \
381 if ( style & (wx) ) { wstyle |= (ms); nModes++; }
382 #else // !__WXDEBUG__
383 #define MAP_MODE_STYLE(wx, ms) \
384 if ( style & (wx) ) wstyle |= (ms);
385 #endif // __WXDEBUG__
386
387 MAP_MODE_STYLE(wxLC_ICON, LVS_ICON)
388 MAP_MODE_STYLE(wxLC_SMALL_ICON, LVS_SMALLICON)
389 MAP_MODE_STYLE(wxLC_LIST, LVS_LIST)
390 MAP_MODE_STYLE(wxLC_REPORT, LVS_REPORT)
391
392 wxASSERT_MSG( nModes == 1,
393 _T("wxListCtrl style should have exactly one mode bit set") );
394
395 #undef MAP_MODE_STYLE
396
397 if ( style & wxLC_ALIGN_LEFT )
398 wstyle |= LVS_ALIGNLEFT;
399
400 if ( style & wxLC_ALIGN_TOP )
401 wstyle |= LVS_ALIGNTOP;
402
403 if ( style & wxLC_AUTOARRANGE )
404 wstyle |= LVS_AUTOARRANGE;
405
406 if ( style & wxLC_NO_SORT_HEADER )
407 wstyle |= LVS_NOSORTHEADER;
408
409 if ( style & wxLC_NO_HEADER )
410 wstyle |= LVS_NOCOLUMNHEADER;
411
412 if ( style & wxLC_EDIT_LABELS )
413 wstyle |= LVS_EDITLABELS;
414
415 if ( style & wxLC_SINGLE_SEL )
416 wstyle |= LVS_SINGLESEL;
417
418 if ( style & wxLC_SORT_ASCENDING )
419 {
420 wstyle |= LVS_SORTASCENDING;
421
422 wxASSERT_MSG( !(style & wxLC_SORT_DESCENDING),
423 _T("can't sort in ascending and descending orders at once") );
424 }
425 else if ( style & wxLC_SORT_DESCENDING )
426 wstyle |= LVS_SORTDESCENDING;
427
428 #if !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
429 if ( style & wxLC_VIRTUAL )
430 {
431 int ver = wxTheApp->GetComCtl32Version();
432 if ( ver < 470 )
433 {
434 wxLogWarning(_("Please install a newer version of comctl32.dll\n(at least version 4.70 is required but you have %d.%02d)\nor this program won't operate correctly."),
435 ver / 100, ver % 100);
436 }
437
438 wstyle |= LVS_OWNERDATA;
439 }
440 #endif // ancient cygwin
441
442 return wstyle;
443 }
444
445 void wxListCtrl::UpdateStyle()
446 {
447 if ( GetHwnd() )
448 {
449 // The new window view style
450 DWORD dwStyleNew = MSWGetStyle(m_windowStyle, NULL);
451
452 // some styles are not returned by MSWGetStyle()
453 if ( IsShown() )
454 dwStyleNew |= WS_VISIBLE;
455
456 // Get the current window style.
457 DWORD dwStyleOld = ::GetWindowLong(GetHwnd(), GWL_STYLE);
458
459 // we don't have wxVSCROLL style, but the list control may have it,
460 // don't change it then
461 dwStyleNew |= dwStyleOld & (WS_HSCROLL | WS_VSCROLL);
462
463 // Only set the window style if the view bits have changed.
464 if ( dwStyleOld != dwStyleNew )
465 {
466 ::SetWindowLong(GetHwnd(), GWL_STYLE, dwStyleNew);
467 }
468 }
469 }
470
471 void wxListCtrl::FreeAllInternalData()
472 {
473 if (m_AnyInternalData)
474 {
475 int n = GetItemCount();
476
477 m_ignoreChangeMessages = true;
478 for (int i = 0; i < n; i++)
479 wxDeleteInternalData(this, i);
480 m_ignoreChangeMessages = false;
481
482 m_AnyInternalData = false;
483 }
484 }
485
486 wxListCtrl::~wxListCtrl()
487 {
488 FreeAllInternalData();
489
490 if ( m_textCtrl )
491 {
492 m_textCtrl->UnsubclassWin();
493 m_textCtrl->SetHWND(0);
494 delete m_textCtrl;
495 m_textCtrl = NULL;
496 }
497
498 if (m_ownsImageListNormal) delete m_imageListNormal;
499 if (m_ownsImageListSmall) delete m_imageListSmall;
500 if (m_ownsImageListState) delete m_imageListState;
501 }
502
503 // ----------------------------------------------------------------------------
504 // set/get/change style
505 // ----------------------------------------------------------------------------
506
507 // Add or remove a single window style
508 void wxListCtrl::SetSingleStyle(long style, bool add)
509 {
510 long flag = GetWindowStyleFlag();
511
512 // Get rid of conflicting styles
513 if ( add )
514 {
515 if ( style & wxLC_MASK_TYPE)
516 flag = flag & ~wxLC_MASK_TYPE;
517 if ( style & wxLC_MASK_ALIGN )
518 flag = flag & ~wxLC_MASK_ALIGN;
519 if ( style & wxLC_MASK_SORT )
520 flag = flag & ~wxLC_MASK_SORT;
521 }
522
523 if ( add )
524 flag |= style;
525 else
526 flag &= ~style;
527
528 SetWindowStyleFlag(flag);
529 }
530
531 // Set the whole window style
532 void wxListCtrl::SetWindowStyleFlag(long flag)
533 {
534 if ( flag != m_windowStyle )
535 {
536 m_windowStyle = flag;
537
538 UpdateStyle();
539
540 Refresh();
541 }
542 }
543
544 // ----------------------------------------------------------------------------
545 // accessors
546 // ----------------------------------------------------------------------------
547
548 /* static */ wxVisualAttributes
549 wxListCtrl::GetClassDefaultAttributes(wxWindowVariant variant)
550 {
551 wxVisualAttributes attrs = GetCompositeControlsDefaultAttributes(variant);
552
553 // common controls have their own default font
554 attrs.font = wxGetCCDefaultFont();
555
556 return attrs;
557 }
558
559 // Sets the foreground, i.e. text, colour
560 bool wxListCtrl::SetForegroundColour(const wxColour& col)
561 {
562 if ( !wxWindow::SetForegroundColour(col) )
563 return false;
564
565 ListView_SetTextColor(GetHwnd(), wxColourToRGB(col));
566
567 return true;
568 }
569
570 // Sets the background colour
571 bool wxListCtrl::SetBackgroundColour(const wxColour& col)
572 {
573 if ( !wxWindow::SetBackgroundColour(col) )
574 return false;
575
576 // we set the same colour for both the "empty" background and the items
577 // background
578 COLORREF color = wxColourToRGB(col);
579 ListView_SetBkColor(GetHwnd(), color);
580 ListView_SetTextBkColor(GetHwnd(), color);
581
582 return true;
583 }
584
585 // Gets information about this column
586 bool wxListCtrl::GetColumn(int col, wxListItem& item) const
587 {
588 LV_COLUMN lvCol;
589 wxZeroMemory(lvCol);
590
591 lvCol.mask = LVCF_WIDTH;
592
593 if ( item.m_mask & wxLIST_MASK_TEXT )
594 {
595 lvCol.mask |= LVCF_TEXT;
596 lvCol.pszText = new wxChar[513];
597 lvCol.cchTextMax = 512;
598 }
599
600 if ( item.m_mask & wxLIST_MASK_FORMAT )
601 {
602 lvCol.mask |= LVCF_FMT;
603 }
604
605 if ( item.m_mask & wxLIST_MASK_IMAGE )
606 {
607 lvCol.mask |= LVCF_IMAGE;
608 }
609
610 bool success = ListView_GetColumn(GetHwnd(), col, &lvCol) != 0;
611
612 // item.m_subItem = lvCol.iSubItem;
613 item.m_width = lvCol.cx;
614
615 if ( (item.m_mask & wxLIST_MASK_TEXT) && lvCol.pszText )
616 {
617 item.m_text = lvCol.pszText;
618 delete[] lvCol.pszText;
619 }
620
621 if ( item.m_mask & wxLIST_MASK_FORMAT )
622 {
623 switch (lvCol.fmt & LVCFMT_JUSTIFYMASK) {
624 case LVCFMT_LEFT:
625 item.m_format = wxLIST_FORMAT_LEFT;
626 break;
627 case LVCFMT_RIGHT:
628 item.m_format = wxLIST_FORMAT_RIGHT;
629 break;
630 case LVCFMT_CENTER:
631 item.m_format = wxLIST_FORMAT_CENTRE;
632 break;
633 default:
634 item.m_format = -1; // Unknown?
635 break;
636 }
637 }
638
639 // the column images were not supported in older versions but how to check
640 // for this? we can't use _WIN32_IE because we always define it to a very
641 // high value, so see if another symbol which is only defined starting from
642 // comctl32.dll 4.70 is available
643 #ifdef NM_CUSTOMDRAW // _WIN32_IE >= 0x0300
644 if ( item.m_mask & wxLIST_MASK_IMAGE )
645 {
646 item.m_image = lvCol.iImage;
647 }
648 #endif // LVCOLUMN::iImage exists
649
650 return success;
651 }
652
653 // Sets information about this column
654 bool wxListCtrl::SetColumn(int col, wxListItem& item)
655 {
656 LV_COLUMN lvCol;
657 wxConvertToMSWListCol(col, item, lvCol);
658
659 return ListView_SetColumn(GetHwnd(), col, &lvCol) != 0;
660 }
661
662 // Gets the column width
663 int wxListCtrl::GetColumnWidth(int col) const
664 {
665 return ListView_GetColumnWidth(GetHwnd(), col);
666 }
667
668 // Sets the column width
669 bool wxListCtrl::SetColumnWidth(int col, int width)
670 {
671 int col2 = col;
672 if ( m_windowStyle & wxLC_LIST )
673 col2 = -1;
674
675 int width2 = width;
676 if ( width2 == wxLIST_AUTOSIZE)
677 width2 = LVSCW_AUTOSIZE;
678 else if ( width2 == wxLIST_AUTOSIZE_USEHEADER)
679 width2 = LVSCW_AUTOSIZE_USEHEADER;
680
681 return ListView_SetColumnWidth(GetHwnd(), col2, width2) != 0;
682 }
683
684 // Gets the number of items that can fit vertically in the
685 // visible area of the list control (list or report view)
686 // or the total number of items in the list control (icon
687 // or small icon view)
688 int wxListCtrl::GetCountPerPage() const
689 {
690 return ListView_GetCountPerPage(GetHwnd());
691 }
692
693 // Gets the edit control for editing labels.
694 wxTextCtrl* wxListCtrl::GetEditControl() const
695 {
696 return m_textCtrl;
697 }
698
699 // Gets information about the item
700 bool wxListCtrl::GetItem(wxListItem& info) const
701 {
702 LV_ITEM lvItem;
703 wxZeroMemory(lvItem);
704
705 lvItem.iItem = info.m_itemId;
706 lvItem.iSubItem = info.m_col;
707
708 if ( info.m_mask & wxLIST_MASK_TEXT )
709 {
710 lvItem.mask |= LVIF_TEXT;
711 lvItem.pszText = new wxChar[513];
712 lvItem.cchTextMax = 512;
713 }
714 else
715 {
716 lvItem.pszText = NULL;
717 }
718
719 if (info.m_mask & wxLIST_MASK_DATA)
720 lvItem.mask |= LVIF_PARAM;
721
722 if (info.m_mask & wxLIST_MASK_IMAGE)
723 lvItem.mask |= LVIF_IMAGE;
724
725 if ( info.m_mask & wxLIST_MASK_STATE )
726 {
727 lvItem.mask |= LVIF_STATE;
728 // the other bits are hardly interesting anyhow
729 lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
730 }
731
732 bool success = ListView_GetItem((HWND)GetHWND(), &lvItem) != 0;
733 if ( !success )
734 {
735 wxLogError(_("Couldn't retrieve information about list control item %d."),
736 lvItem.iItem);
737 }
738 else
739 {
740 // give NULL as hwnd as we already have everything we need
741 wxConvertFromMSWListItem(NULL, info, lvItem);
742 }
743
744 if (lvItem.pszText)
745 delete[] lvItem.pszText;
746
747 return success;
748 }
749
750 // Sets information about the item
751 bool wxListCtrl::SetItem(wxListItem& info)
752 {
753 LV_ITEM item;
754 wxConvertToMSWListItem(this, info, item);
755
756 // we never update the lParam if it contains our pointer
757 // to the wxListItemInternalData structure
758 item.mask &= ~LVIF_PARAM;
759
760 // check if setting attributes or lParam
761 if (info.HasAttributes() || (info.m_mask & wxLIST_MASK_DATA))
762 {
763 // get internal item data
764 // perhaps a cache here ?
765 wxListItemInternalData *data = wxGetInternalData(this, info.m_itemId);
766
767 if (! data)
768 {
769 // need to set it
770 m_AnyInternalData = true;
771 data = new wxListItemInternalData();
772 item.lParam = (LPARAM) data;
773 item.mask |= LVIF_PARAM;
774 };
775
776
777 // user data
778 if (info.m_mask & wxLIST_MASK_DATA)
779 data->lParam = info.m_data;
780
781 // attributes
782 if (info.HasAttributes())
783 {
784 if (data->attr)
785 *data->attr = *info.GetAttributes();
786 else
787 data->attr = new wxListItemAttr(*info.GetAttributes());
788 };
789 };
790
791
792 // we could be changing only the attribute in which case we don't need to
793 // call ListView_SetItem() at all
794 if ( item.mask )
795 {
796 item.cchTextMax = 0;
797 if ( !ListView_SetItem(GetHwnd(), &item) )
798 {
799 wxLogDebug(_T("ListView_SetItem() failed"));
800
801 return false;
802 }
803 }
804
805 // we need to update the item immediately to show the new image
806 bool updateNow = (info.m_mask & wxLIST_MASK_IMAGE) != 0;
807
808 // check whether it has any custom attributes
809 if ( info.HasAttributes() )
810 {
811 m_hasAnyAttr = true;
812
813 // if the colour has changed, we must redraw the item
814 updateNow = true;
815 }
816
817 if ( updateNow )
818 {
819 // we need this to make the change visible right now
820 RefreshItem(item.iItem);
821 }
822
823 return true;
824 }
825
826 long wxListCtrl::SetItem(long index, int col, const wxString& label, int imageId)
827 {
828 wxListItem info;
829 info.m_text = label;
830 info.m_mask = wxLIST_MASK_TEXT;
831 info.m_itemId = index;
832 info.m_col = col;
833 if ( imageId > -1 )
834 {
835 info.m_image = imageId;
836 info.m_mask |= wxLIST_MASK_IMAGE;
837 }
838 return SetItem(info);
839 }
840
841
842 // Gets the item state
843 int wxListCtrl::GetItemState(long item, long stateMask) const
844 {
845 wxListItem info;
846
847 info.m_mask = wxLIST_MASK_STATE;
848 info.m_stateMask = stateMask;
849 info.m_itemId = item;
850
851 if (!GetItem(info))
852 return 0;
853
854 return info.m_state;
855 }
856
857 // Sets the item state
858 bool wxListCtrl::SetItemState(long item, long state, long stateMask)
859 {
860 // NB: don't use SetItem() here as it doesn't work with the virtual list
861 // controls
862 LV_ITEM lvItem;
863 wxZeroMemory(lvItem);
864
865 wxConvertToMSWFlags(state, stateMask, lvItem);
866
867 // for the virtual list controls we need to refresh the previously focused
868 // item manually when changing focus without changing selection
869 // programmatically because otherwise it keeps its focus rectangle until
870 // next repaint (yet another comctl32 bug)
871 long focusOld;
872 if ( IsVirtual() &&
873 (stateMask & wxLIST_STATE_FOCUSED) &&
874 (state & wxLIST_STATE_FOCUSED) )
875 {
876 focusOld = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
877 }
878 else
879 {
880 focusOld = -1;
881 }
882
883 if ( !::SendMessage(GetHwnd(), LVM_SETITEMSTATE,
884 (WPARAM)item, (LPARAM)&lvItem) )
885 {
886 wxLogLastError(_T("ListView_SetItemState"));
887
888 return false;
889 }
890
891 if ( focusOld != -1 )
892 {
893 // no need to refresh the item if it was previously selected, it would
894 // only result in annoying flicker
895 if ( !(GetItemState(focusOld,
896 wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED) )
897 {
898 RefreshItem(focusOld);
899 }
900 }
901
902 return true;
903 }
904
905 // Sets the item image
906 #if WXWIN_COMPATIBILITY_2_4
907 bool wxListCtrl::SetItemImage(long item, int image, int WXUNUSED(selImage))
908 {
909 wxListItem info;
910
911 info.m_mask = wxLIST_MASK_IMAGE;
912 info.m_image = image;
913 info.m_itemId = item;
914
915 return SetItem(info);
916 }
917 #endif
918
919 bool wxListCtrl::SetItemImage(long item, int image)
920 {
921 wxListItem info;
922
923 info.m_mask = wxLIST_MASK_IMAGE;
924 info.m_image = image;
925 info.m_itemId = item;
926
927 return SetItem(info);
928 }
929
930 // Gets the item text
931 wxString wxListCtrl::GetItemText(long item) const
932 {
933 wxListItem info;
934
935 info.m_mask = wxLIST_MASK_TEXT;
936 info.m_itemId = item;
937
938 if (!GetItem(info))
939 return wxEmptyString;
940 return info.m_text;
941 }
942
943 // Sets the item text
944 void wxListCtrl::SetItemText(long item, const wxString& str)
945 {
946 wxListItem info;
947
948 info.m_mask = wxLIST_MASK_TEXT;
949 info.m_itemId = item;
950 info.m_text = str;
951
952 SetItem(info);
953 }
954
955 // Gets the item data
956 wxUIntPtr wxListCtrl::GetItemData(long item) const
957 {
958 wxListItem info;
959
960 info.m_mask = wxLIST_MASK_DATA;
961 info.m_itemId = item;
962
963 if (!GetItem(info))
964 return 0;
965 return info.m_data;
966 }
967
968 // Sets the item data
969 bool wxListCtrl::SetItemData(long item, long data)
970 {
971 wxListItem info;
972
973 info.m_mask = wxLIST_MASK_DATA;
974 info.m_itemId = item;
975 info.m_data = data;
976
977 return SetItem(info);
978 }
979
980 wxRect wxListCtrl::GetViewRect() const
981 {
982 wxASSERT_MSG( !HasFlag(wxLC_REPORT | wxLC_LIST),
983 _T("wxListCtrl::GetViewRect() only works in icon mode") );
984
985 RECT rc;
986 if ( !ListView_GetViewRect(GetHwnd(), &rc) )
987 {
988 wxLogDebug(_T("ListView_GetViewRect() failed."));
989
990 wxZeroMemory(rc);
991 }
992
993 wxRect rect;
994 wxCopyRECTToRect(rc, rect);
995
996 return rect;
997 }
998
999 // Gets the item rectangle
1000 bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const
1001 {
1002 RECT rectWin;
1003
1004 int codeWin;
1005 if ( code == wxLIST_RECT_BOUNDS )
1006 codeWin = LVIR_BOUNDS;
1007 else if ( code == wxLIST_RECT_ICON )
1008 codeWin = LVIR_ICON;
1009 else if ( code == wxLIST_RECT_LABEL )
1010 codeWin = LVIR_LABEL;
1011 else
1012 {
1013 wxFAIL_MSG( _T("incorrect code in GetItemRect()") );
1014
1015 codeWin = LVIR_BOUNDS;
1016 }
1017
1018 bool success = ListView_GetItemRect(GetHwnd(), (int) item, &rectWin, codeWin) != 0;
1019
1020 rect.x = rectWin.left;
1021 rect.y = rectWin.top;
1022 rect.width = rectWin.right - rectWin.left;
1023 rect.height = rectWin.bottom - rectWin.top;
1024
1025 return success;
1026 }
1027
1028 // Gets the item position
1029 bool wxListCtrl::GetItemPosition(long item, wxPoint& pos) const
1030 {
1031 POINT pt;
1032
1033 bool success = (ListView_GetItemPosition(GetHwnd(), (int) item, &pt) != 0);
1034
1035 pos.x = pt.x; pos.y = pt.y;
1036 return success;
1037 }
1038
1039 // Sets the item position.
1040 bool wxListCtrl::SetItemPosition(long item, const wxPoint& pos)
1041 {
1042 return (ListView_SetItemPosition(GetHwnd(), (int) item, pos.x, pos.y) != 0);
1043 }
1044
1045 // Gets the number of items in the list control
1046 int wxListCtrl::GetItemCount() const
1047 {
1048 return m_count;
1049 }
1050
1051 wxSize wxListCtrl::GetItemSpacing() const
1052 {
1053 const int spacing = ListView_GetItemSpacing(GetHwnd(), (BOOL)HasFlag(wxLC_SMALL_ICON));
1054
1055 return wxSize(LOWORD(spacing), HIWORD(spacing));
1056 }
1057
1058 int wxListCtrl::GetItemSpacing(bool isSmall) const
1059 {
1060 return ListView_GetItemSpacing(GetHwnd(), (BOOL) isSmall);
1061 }
1062
1063 void wxListCtrl::SetItemTextColour( long item, const wxColour &col )
1064 {
1065 wxListItem info;
1066 info.m_itemId = item;
1067 info.SetTextColour( col );
1068 SetItem( info );
1069 }
1070
1071 wxColour wxListCtrl::GetItemTextColour( long item ) const
1072 {
1073 wxColour col;
1074 wxListItemInternalData *data = wxGetInternalData(this, item);
1075 if ( data && data->attr )
1076 col = data->attr->GetTextColour();
1077
1078 return col;
1079 }
1080
1081 void wxListCtrl::SetItemBackgroundColour( long item, const wxColour &col )
1082 {
1083 wxListItem info;
1084 info.m_itemId = item;
1085 info.SetBackgroundColour( col );
1086 SetItem( info );
1087 }
1088
1089 wxColour wxListCtrl::GetItemBackgroundColour( long item ) const
1090 {
1091 wxColour col;
1092 wxListItemInternalData *data = wxGetInternalData(this, item);
1093 if ( data && data->attr )
1094 col = data->attr->GetBackgroundColour();
1095
1096 return col;
1097 }
1098
1099 // Gets the number of selected items in the list control
1100 int wxListCtrl::GetSelectedItemCount() const
1101 {
1102 return ListView_GetSelectedCount(GetHwnd());
1103 }
1104
1105 // Gets the text colour of the listview
1106 wxColour wxListCtrl::GetTextColour() const
1107 {
1108 COLORREF ref = ListView_GetTextColor(GetHwnd());
1109 wxColour col(GetRValue(ref), GetGValue(ref), GetBValue(ref));
1110 return col;
1111 }
1112
1113 // Sets the text colour of the listview
1114 void wxListCtrl::SetTextColour(const wxColour& col)
1115 {
1116 ListView_SetTextColor(GetHwnd(), PALETTERGB(col.Red(), col.Green(), col.Blue()));
1117 }
1118
1119 // Gets the index of the topmost visible item when in
1120 // list or report view
1121 long wxListCtrl::GetTopItem() const
1122 {
1123 return (long) ListView_GetTopIndex(GetHwnd());
1124 }
1125
1126 // Searches for an item, starting from 'item'.
1127 // 'geometry' is one of
1128 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1129 // 'state' is a state bit flag, one or more of
1130 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1131 // item can be -1 to find the first item that matches the
1132 // specified flags.
1133 // Returns the item or -1 if unsuccessful.
1134 long wxListCtrl::GetNextItem(long item, int geom, int state) const
1135 {
1136 long flags = 0;
1137
1138 if ( geom == wxLIST_NEXT_ABOVE )
1139 flags |= LVNI_ABOVE;
1140 if ( geom == wxLIST_NEXT_ALL )
1141 flags |= LVNI_ALL;
1142 if ( geom == wxLIST_NEXT_BELOW )
1143 flags |= LVNI_BELOW;
1144 if ( geom == wxLIST_NEXT_LEFT )
1145 flags |= LVNI_TOLEFT;
1146 if ( geom == wxLIST_NEXT_RIGHT )
1147 flags |= LVNI_TORIGHT;
1148
1149 if ( state & wxLIST_STATE_CUT )
1150 flags |= LVNI_CUT;
1151 if ( state & wxLIST_STATE_DROPHILITED )
1152 flags |= LVNI_DROPHILITED;
1153 if ( state & wxLIST_STATE_FOCUSED )
1154 flags |= LVNI_FOCUSED;
1155 if ( state & wxLIST_STATE_SELECTED )
1156 flags |= LVNI_SELECTED;
1157
1158 return (long) ListView_GetNextItem(GetHwnd(), item, flags);
1159 }
1160
1161
1162 wxImageList *wxListCtrl::GetImageList(int which) const
1163 {
1164 if ( which == wxIMAGE_LIST_NORMAL )
1165 {
1166 return m_imageListNormal;
1167 }
1168 else if ( which == wxIMAGE_LIST_SMALL )
1169 {
1170 return m_imageListSmall;
1171 }
1172 else if ( which == wxIMAGE_LIST_STATE )
1173 {
1174 return m_imageListState;
1175 }
1176 return NULL;
1177 }
1178
1179 void wxListCtrl::SetImageList(wxImageList *imageList, int which)
1180 {
1181 int flags = 0;
1182 if ( which == wxIMAGE_LIST_NORMAL )
1183 {
1184 flags = LVSIL_NORMAL;
1185 if (m_ownsImageListNormal) delete m_imageListNormal;
1186 m_imageListNormal = imageList;
1187 m_ownsImageListNormal = false;
1188 }
1189 else if ( which == wxIMAGE_LIST_SMALL )
1190 {
1191 flags = LVSIL_SMALL;
1192 if (m_ownsImageListSmall) delete m_imageListSmall;
1193 m_imageListSmall = imageList;
1194 m_ownsImageListSmall = false;
1195 }
1196 else if ( which == wxIMAGE_LIST_STATE )
1197 {
1198 flags = LVSIL_STATE;
1199 if (m_ownsImageListState) delete m_imageListState;
1200 m_imageListState = imageList;
1201 m_ownsImageListState = false;
1202 }
1203 ListView_SetImageList(GetHwnd(), (HIMAGELIST) imageList ? imageList->GetHIMAGELIST() : 0, flags);
1204 }
1205
1206 void wxListCtrl::AssignImageList(wxImageList *imageList, int which)
1207 {
1208 SetImageList(imageList, which);
1209 if ( which == wxIMAGE_LIST_NORMAL )
1210 m_ownsImageListNormal = true;
1211 else if ( which == wxIMAGE_LIST_SMALL )
1212 m_ownsImageListSmall = true;
1213 else if ( which == wxIMAGE_LIST_STATE )
1214 m_ownsImageListState = true;
1215 }
1216
1217 // ----------------------------------------------------------------------------
1218 // Operations
1219 // ----------------------------------------------------------------------------
1220
1221 // Arranges the items
1222 bool wxListCtrl::Arrange(int flag)
1223 {
1224 UINT code = 0;
1225 if ( flag == wxLIST_ALIGN_LEFT )
1226 code = LVA_ALIGNLEFT;
1227 else if ( flag == wxLIST_ALIGN_TOP )
1228 code = LVA_ALIGNTOP;
1229 else if ( flag == wxLIST_ALIGN_DEFAULT )
1230 code = LVA_DEFAULT;
1231 else if ( flag == wxLIST_ALIGN_SNAP_TO_GRID )
1232 code = LVA_SNAPTOGRID;
1233
1234 return (ListView_Arrange(GetHwnd(), code) != 0);
1235 }
1236
1237 // Deletes an item
1238 bool wxListCtrl::DeleteItem(long item)
1239 {
1240 if ( !ListView_DeleteItem(GetHwnd(), (int) item) )
1241 {
1242 wxLogLastError(_T("ListView_DeleteItem"));
1243 return false;
1244 }
1245
1246 m_count -= 1;
1247 wxASSERT_MSG( m_count == ListView_GetItemCount(GetHwnd()),
1248 wxT("m_count should match ListView_GetItemCount"));
1249
1250 // the virtual list control doesn't refresh itself correctly, help it
1251 if ( IsVirtual() )
1252 {
1253 // we need to refresh all the lines below the one which was deleted
1254 wxRect rectItem;
1255 if ( item > 0 && GetItemCount() )
1256 {
1257 GetItemRect(item - 1, rectItem);
1258 }
1259 else
1260 {
1261 rectItem.y =
1262 rectItem.height = 0;
1263 }
1264
1265 wxRect rectWin = GetRect();
1266 rectWin.height = rectWin.GetBottom() - rectItem.GetBottom();
1267 rectWin.y = rectItem.GetBottom();
1268
1269 RefreshRect(rectWin);
1270 }
1271
1272 return true;
1273 }
1274
1275 // Deletes all items
1276 bool wxListCtrl::DeleteAllItems()
1277 {
1278 return ListView_DeleteAllItems(GetHwnd()) != 0;
1279 }
1280
1281 // Deletes all items
1282 bool wxListCtrl::DeleteAllColumns()
1283 {
1284 while ( m_colCount > 0 )
1285 {
1286 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
1287 {
1288 wxLogLastError(wxT("ListView_DeleteColumn"));
1289
1290 return false;
1291 }
1292
1293 m_colCount--;
1294 }
1295
1296 wxASSERT_MSG( m_colCount == 0, wxT("no columns should be left") );
1297
1298 return true;
1299 }
1300
1301 // Deletes a column
1302 bool wxListCtrl::DeleteColumn(int col)
1303 {
1304 bool success = (ListView_DeleteColumn(GetHwnd(), col) != 0);
1305
1306 if ( success && (m_colCount > 0) )
1307 m_colCount --;
1308 return success;
1309 }
1310
1311 // Clears items, and columns if there are any.
1312 void wxListCtrl::ClearAll()
1313 {
1314 DeleteAllItems();
1315 if ( m_colCount > 0 )
1316 DeleteAllColumns();
1317 }
1318
1319 wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass)
1320 {
1321 wxASSERT( (textControlClass->IsKindOf(CLASSINFO(wxTextCtrl))) );
1322
1323 // ListView_EditLabel requires that the list has focus.
1324 SetFocus();
1325
1326 WXHWND hWnd = (WXHWND) ListView_EditLabel(GetHwnd(), item);
1327 if ( !hWnd )
1328 {
1329 // failed to start editing
1330 return NULL;
1331 }
1332
1333 // [re]create the text control wrapping the HWND we got
1334 if ( m_textCtrl )
1335 {
1336 m_textCtrl->UnsubclassWin();
1337 m_textCtrl->SetHWND(0);
1338 delete m_textCtrl;
1339 }
1340
1341 m_textCtrl = (wxTextCtrl *)textControlClass->CreateObject();
1342 m_textCtrl->SetHWND(hWnd);
1343 m_textCtrl->SubclassWin(hWnd);
1344 m_textCtrl->SetParent(this);
1345
1346 // we must disallow TABbing away from the control while the edit contol is
1347 // shown because this leaves it in some strange state (just try removing
1348 // this line and then pressing TAB while editing an item in listctrl
1349 // inside a panel)
1350 m_textCtrl->SetWindowStyle(m_textCtrl->GetWindowStyle() | wxTE_PROCESS_TAB);
1351
1352 return m_textCtrl;
1353 }
1354
1355 // End label editing, optionally cancelling the edit
1356 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel))
1357 {
1358 wxFAIL_MSG( _T("not implemented") );
1359
1360 return false;
1361 }
1362
1363 // Ensures this item is visible
1364 bool wxListCtrl::EnsureVisible(long item)
1365 {
1366 return ListView_EnsureVisible(GetHwnd(), (int) item, FALSE) != FALSE;
1367 }
1368
1369 // Find an item whose label matches this string, starting from the item after 'start'
1370 // or the beginning if 'start' is -1.
1371 long wxListCtrl::FindItem(long start, const wxString& str, bool partial)
1372 {
1373 LV_FINDINFO findInfo;
1374
1375 findInfo.flags = LVFI_STRING;
1376 if ( partial )
1377 findInfo.flags |= LVFI_PARTIAL;
1378 findInfo.psz = str;
1379
1380 // ListView_FindItem() excludes the first item from search and to look
1381 // through all the items you need to start from -1 which is unnatural and
1382 // inconsistent with the generic version - so we adjust the index
1383 if (start != -1)
1384 start --;
1385 return ListView_FindItem(GetHwnd(), (int) start, &findInfo);
1386 }
1387
1388 // Find an item whose data matches this data, starting from the item after 'start'
1389 // or the beginning if 'start' is -1.
1390 // NOTE : Lindsay Mathieson - 14-July-2002
1391 // No longer use ListView_FindItem as the data attribute is now stored
1392 // in a wxListItemInternalData structure refernced by the actual lParam
1393 long wxListCtrl::FindItem(long start, wxUIntPtr data)
1394 {
1395 long idx = start + 1;
1396 long count = GetItemCount();
1397
1398 while (idx < count)
1399 {
1400 if (GetItemData(idx) == data)
1401 return idx;
1402 idx++;
1403 };
1404
1405 return -1;
1406 }
1407
1408 // Find an item nearest this position in the specified direction, starting from
1409 // the item after 'start' or the beginning if 'start' is -1.
1410 long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction)
1411 {
1412 LV_FINDINFO findInfo;
1413
1414 findInfo.flags = LVFI_NEARESTXY;
1415 findInfo.pt.x = pt.x;
1416 findInfo.pt.y = pt.y;
1417 findInfo.vkDirection = VK_RIGHT;
1418
1419 if ( direction == wxLIST_FIND_UP )
1420 findInfo.vkDirection = VK_UP;
1421 else if ( direction == wxLIST_FIND_DOWN )
1422 findInfo.vkDirection = VK_DOWN;
1423 else if ( direction == wxLIST_FIND_LEFT )
1424 findInfo.vkDirection = VK_LEFT;
1425 else if ( direction == wxLIST_FIND_RIGHT )
1426 findInfo.vkDirection = VK_RIGHT;
1427
1428 return ListView_FindItem(GetHwnd(), (int) start, & findInfo);
1429 }
1430
1431 // Determines which item (if any) is at the specified point,
1432 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1433 long wxListCtrl::HitTest(const wxPoint& point, int& flags)
1434 {
1435 LV_HITTESTINFO hitTestInfo;
1436 hitTestInfo.pt.x = (int) point.x;
1437 hitTestInfo.pt.y = (int) point.y;
1438
1439 ListView_HitTest(GetHwnd(), & hitTestInfo);
1440
1441 flags = 0;
1442 if ( hitTestInfo.flags & LVHT_ABOVE )
1443 flags |= wxLIST_HITTEST_ABOVE;
1444 if ( hitTestInfo.flags & LVHT_BELOW )
1445 flags |= wxLIST_HITTEST_BELOW;
1446 if ( hitTestInfo.flags & LVHT_NOWHERE )
1447 flags |= wxLIST_HITTEST_NOWHERE;
1448 if ( hitTestInfo.flags & LVHT_ONITEMICON )
1449 flags |= wxLIST_HITTEST_ONITEMICON;
1450 if ( hitTestInfo.flags & LVHT_ONITEMLABEL )
1451 flags |= wxLIST_HITTEST_ONITEMLABEL;
1452 if ( hitTestInfo.flags & LVHT_ONITEMSTATEICON )
1453 flags |= wxLIST_HITTEST_ONITEMSTATEICON;
1454 if ( hitTestInfo.flags & LVHT_TOLEFT )
1455 flags |= wxLIST_HITTEST_TOLEFT;
1456 if ( hitTestInfo.flags & LVHT_TORIGHT )
1457 flags |= wxLIST_HITTEST_TORIGHT;
1458
1459 return (long) hitTestInfo.iItem;
1460 }
1461
1462 // Inserts an item, returning the index of the new item if successful,
1463 // -1 otherwise.
1464 long wxListCtrl::InsertItem(wxListItem& info)
1465 {
1466 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1467
1468 LV_ITEM item;
1469 wxConvertToMSWListItem(this, info, item);
1470 item.mask &= ~LVIF_PARAM;
1471
1472 // check wether we need to allocate our internal data
1473 bool needInternalData = ((info.m_mask & wxLIST_MASK_DATA) || info.HasAttributes());
1474 if (needInternalData)
1475 {
1476 m_AnyInternalData = true;
1477 item.mask |= LVIF_PARAM;
1478
1479 // internal stucture that manages data
1480 wxListItemInternalData *data = new wxListItemInternalData();
1481 item.lParam = (LPARAM) data;
1482
1483 if (info.m_mask & wxLIST_MASK_DATA)
1484 data->lParam = info.m_data;
1485
1486 // check whether it has any custom attributes
1487 if ( info.HasAttributes() )
1488 {
1489 // take copy of attributes
1490 data->attr = new wxListItemAttr(*info.GetAttributes());
1491
1492 // and remember that we have some now...
1493 m_hasAnyAttr = true;
1494 }
1495 };
1496
1497 long rv = ListView_InsertItem(GetHwnd(), & item);
1498
1499 m_count++;
1500 wxASSERT_MSG( m_count == ListView_GetItemCount(GetHwnd()),
1501 wxT("m_count should match ListView_GetItemCount"));
1502
1503 return rv;
1504 }
1505
1506 long wxListCtrl::InsertItem(long index, const wxString& label)
1507 {
1508 wxListItem info;
1509 info.m_text = label;
1510 info.m_mask = wxLIST_MASK_TEXT;
1511 info.m_itemId = index;
1512 return InsertItem(info);
1513 }
1514
1515 // Inserts an image item
1516 long wxListCtrl::InsertItem(long index, int imageIndex)
1517 {
1518 wxListItem info;
1519 info.m_image = imageIndex;
1520 info.m_mask = wxLIST_MASK_IMAGE;
1521 info.m_itemId = index;
1522 return InsertItem(info);
1523 }
1524
1525 // Inserts an image/string item
1526 long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex)
1527 {
1528 wxListItem info;
1529 info.m_image = imageIndex;
1530 info.m_text = label;
1531 info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT;
1532 info.m_itemId = index;
1533 return InsertItem(info);
1534 }
1535
1536 // For list view mode (only), inserts a column.
1537 long wxListCtrl::InsertColumn(long col, wxListItem& item)
1538 {
1539 LV_COLUMN lvCol;
1540 wxConvertToMSWListCol(col, item, lvCol);
1541
1542 if ( !(lvCol.mask & LVCF_WIDTH) )
1543 {
1544 // always give some width to the new column: this one is compatible
1545 // with the generic version
1546 lvCol.mask |= LVCF_WIDTH;
1547 lvCol.cx = 80;
1548 }
1549
1550 long n = ListView_InsertColumn(GetHwnd(), col, &lvCol);
1551 if ( n != -1 )
1552 {
1553 m_colCount++;
1554 }
1555 else // failed to insert?
1556 {
1557 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1558 lvCol.pszText);
1559 }
1560
1561 return n;
1562 }
1563
1564 long wxListCtrl::InsertColumn(long col,
1565 const wxString& heading,
1566 int format,
1567 int width)
1568 {
1569 wxListItem item;
1570 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
1571 item.m_text = heading;
1572 if ( width > -1 )
1573 {
1574 item.m_mask |= wxLIST_MASK_WIDTH;
1575 item.m_width = width;
1576 }
1577 item.m_format = format;
1578
1579 return InsertColumn(col, item);
1580 }
1581
1582 // scroll the control by the given number of pixels (exception: in list view,
1583 // dx is interpreted as number of columns)
1584 bool wxListCtrl::ScrollList(int dx, int dy)
1585 {
1586 if ( !ListView_Scroll(GetHwnd(), dx, dy) )
1587 {
1588 wxLogDebug(_T("ListView_Scroll(%d, %d) failed"), dx, dy);
1589
1590 return false;
1591 }
1592
1593 return true;
1594 }
1595
1596 // Sort items.
1597
1598 // fn is a function which takes 3 long arguments: item1, item2, data.
1599 // item1 is the long data associated with a first item (NOT the index).
1600 // item2 is the long data associated with a second item (NOT the index).
1601 // data is the same value as passed to SortItems.
1602 // The return value is a negative number if the first item should precede the second
1603 // item, a positive number of the second item should precede the first,
1604 // or zero if the two items are equivalent.
1605
1606 // data is arbitrary data to be passed to the sort function.
1607
1608 // Internal structures for proxying the user compare function
1609 // so that we can pass it the *real* user data
1610
1611 // translate lParam data and call user func
1612 struct wxInternalDataSort
1613 {
1614 wxListCtrlCompare user_fn;
1615 long data;
1616 };
1617
1618 int CALLBACK wxInternalDataCompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
1619 {
1620 struct wxInternalDataSort *internalData = (struct wxInternalDataSort *) lParamSort;
1621
1622 wxListItemInternalData *data1 = (wxListItemInternalData *) lParam1;
1623 wxListItemInternalData *data2 = (wxListItemInternalData *) lParam2;
1624
1625 long d1 = (data1 == NULL ? 0 : data1->lParam);
1626 long d2 = (data2 == NULL ? 0 : data2->lParam);
1627
1628 return internalData->user_fn(d1, d2, internalData->data);
1629
1630 };
1631
1632 bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data)
1633 {
1634 struct wxInternalDataSort internalData;
1635 internalData.user_fn = fn;
1636 internalData.data = data;
1637
1638 // WPARAM cast is needed for mingw/cygwin
1639 if ( !ListView_SortItems(GetHwnd(),
1640 wxInternalDataCompareFunc,
1641 (WPARAM) &internalData) )
1642 {
1643 wxLogDebug(_T("ListView_SortItems() failed"));
1644
1645 return false;
1646 }
1647
1648 return true;
1649 }
1650
1651
1652
1653 // ----------------------------------------------------------------------------
1654 // message processing
1655 // ----------------------------------------------------------------------------
1656
1657 bool wxListCtrl::MSWCommand(WXUINT cmd, WXWORD id)
1658 {
1659 if (cmd == EN_UPDATE)
1660 {
1661 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, id);
1662 event.SetEventObject( this );
1663 ProcessCommand(event);
1664 return true;
1665 }
1666 else if (cmd == EN_KILLFOCUS)
1667 {
1668 wxCommandEvent event(wxEVT_KILL_FOCUS, id);
1669 event.SetEventObject( this );
1670 ProcessCommand(event);
1671 return true;
1672 }
1673 else
1674 return false;
1675 }
1676
1677 bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
1678 {
1679
1680 // prepare the event
1681 // -----------------
1682
1683 wxListEvent event(wxEVT_NULL, m_windowId);
1684 event.SetEventObject(this);
1685
1686 wxEventType eventType = wxEVT_NULL;
1687
1688 NMHDR *nmhdr = (NMHDR *)lParam;
1689
1690 // if your compiler is as broken as this, you should really change it: this
1691 // code is needed for normal operation! #ifdef below is only useful for
1692 // automatic rebuilds which are done with a very old compiler version
1693 #ifdef HDN_BEGINTRACKA
1694
1695 // check for messages from the header (in report view)
1696 HWND hwndHdr = ListView_GetHeader(GetHwnd());
1697
1698 // is it a message from the header?
1699 if ( nmhdr->hwndFrom == hwndHdr )
1700 {
1701 HD_NOTIFY *nmHDR = (HD_NOTIFY *)nmhdr;
1702
1703 event.m_itemIndex = -1;
1704
1705 switch ( nmhdr->code )
1706 {
1707 // yet another comctl32.dll bug: under NT/W2K it sends Unicode
1708 // TRACK messages even to ANSI programs: on my system I get
1709 // HDN_BEGINTRACKW and HDN_ENDTRACKA and no HDN_TRACK at all!
1710 //
1711 // work around is to simply catch both versions and hope that it
1712 // works (why should this message exist in ANSI and Unicode is
1713 // beyond me as it doesn't deal with strings at all...)
1714 //
1715 // note that fr HDN_TRACK another possibility could be to use
1716 // HDN_ITEMCHANGING but it is sent even after HDN_ENDTRACK and when
1717 // something other than the item width changes so we'd have to
1718 // filter out the unwanted events then
1719 case HDN_BEGINTRACKA:
1720 case HDN_BEGINTRACKW:
1721 eventType = wxEVT_COMMAND_LIST_COL_BEGIN_DRAG;
1722 // fall through
1723
1724 case HDN_TRACKA:
1725 case HDN_TRACKW:
1726 if ( eventType == wxEVT_NULL )
1727 eventType = wxEVT_COMMAND_LIST_COL_DRAGGING;
1728 // fall through
1729
1730 case HDN_ENDTRACKA:
1731 case HDN_ENDTRACKW:
1732 if ( eventType == wxEVT_NULL )
1733 eventType = wxEVT_COMMAND_LIST_COL_END_DRAG;
1734
1735 event.m_item.m_width = nmHDR->pitem->cxy;
1736 event.m_col = nmHDR->iItem;
1737 break;
1738
1739 #if defined(__WXWINCE__) && !defined(__HANDHELDPC__) && _WIN32_WCE < 400
1740 case GN_CONTEXTMENU:
1741 #endif //__WXWINCE__
1742 case NM_RCLICK:
1743 {
1744 eventType = wxEVT_COMMAND_LIST_COL_RIGHT_CLICK;
1745 event.m_col = -1;
1746
1747 // find the column clicked: we have to search for it
1748 // ourselves as the notification message doesn't provide
1749 // this info
1750
1751 // where did the click occur?
1752 POINT ptClick;
1753 #if defined(__WXWINCE__) && !defined(__HANDHELDPC__) && _WIN32_WCE < 400
1754 if(nmhdr->code == GN_CONTEXTMENU) {
1755 ptClick = ((NMRGINFO*)nmhdr)->ptAction;
1756 } else
1757 #endif //__WXWINCE__
1758 if ( !::GetCursorPos(&ptClick) )
1759 {
1760 wxLogLastError(_T("GetCursorPos"));
1761 }
1762
1763 if ( !::ScreenToClient(GetHwnd(), &ptClick) )
1764 {
1765 wxLogLastError(_T("ScreenToClient(listctrl header)"));
1766 }
1767
1768 event.m_pointDrag.x = ptClick.x;
1769 event.m_pointDrag.y = ptClick.y;
1770
1771 int colCount = Header_GetItemCount(hwndHdr);
1772
1773 RECT rect;
1774 for ( int col = 0; col < colCount; col++ )
1775 {
1776 if ( Header_GetItemRect(hwndHdr, col, &rect) )
1777 {
1778 if ( ::PtInRect(&rect, ptClick) )
1779 {
1780 event.m_col = col;
1781 break;
1782 }
1783 }
1784 }
1785 }
1786 break;
1787
1788 case HDN_GETDISPINFOW:
1789 // letting Windows XP handle this message results in mysterious
1790 // crashes in comctl32.dll seemingly because of bad message
1791 // parameters
1792 //
1793 // I have no idea what is the real cause of the bug (which is,
1794 // just to make things interesting, is impossible to reproduce
1795 // reliably) but ignoring all these messages does fix it and
1796 // doesn't seem to have any negative consequences
1797 return true;
1798
1799 default:
1800 return wxControl::MSWOnNotify(idCtrl, lParam, result);
1801 }
1802 }
1803 else
1804 #endif // defined(HDN_BEGINTRACKA)
1805 if ( nmhdr->hwndFrom == GetHwnd() )
1806 {
1807 // almost all messages use NM_LISTVIEW
1808 NM_LISTVIEW *nmLV = (NM_LISTVIEW *)nmhdr;
1809
1810 const int iItem = nmLV->iItem;
1811
1812
1813 // FreeAllInternalData will cause LVN_ITEMCHANG* messages, which can be
1814 // ignored for efficiency. It is done here because the internal data is in the
1815 // process of being deleted so we don't want to try and access it below.
1816 if ( m_ignoreChangeMessages &&
1817 ( (nmLV->hdr.code == LVN_ITEMCHANGED) || (nmLV->hdr.code == LVN_ITEMCHANGING)))
1818 {
1819 return true;
1820 }
1821
1822
1823 // If we have a valid item then check if there is a data value
1824 // associated with it and put it in the event.
1825 if ( iItem >= 0 && iItem < GetItemCount() )
1826 {
1827 wxListItemInternalData *internaldata =
1828 wxGetInternalData(GetHwnd(), iItem);
1829
1830 if ( internaldata )
1831 event.m_item.m_data = internaldata->lParam;
1832 }
1833
1834
1835 switch ( nmhdr->code )
1836 {
1837 case LVN_BEGINRDRAG:
1838 eventType = wxEVT_COMMAND_LIST_BEGIN_RDRAG;
1839 // fall through
1840
1841 case LVN_BEGINDRAG:
1842 if ( eventType == wxEVT_NULL )
1843 {
1844 eventType = wxEVT_COMMAND_LIST_BEGIN_DRAG;
1845 }
1846
1847 event.m_itemIndex = iItem;
1848 event.m_pointDrag.x = nmLV->ptAction.x;
1849 event.m_pointDrag.y = nmLV->ptAction.y;
1850 break;
1851
1852 // NB: we have to handle both *A and *W versions here because some
1853 // versions of comctl32.dll send ANSI messages even to the
1854 // Unicode windows
1855 case LVN_BEGINLABELEDITA:
1856 case LVN_BEGINLABELEDITW:
1857 {
1858 wxLV_ITEM item;
1859 if ( nmhdr->code == LVN_BEGINLABELEDITA )
1860 {
1861 item.Init(((LV_DISPINFOA *)lParam)->item);
1862 }
1863 else // LVN_BEGINLABELEDITW
1864 {
1865 item.Init(((LV_DISPINFOW *)lParam)->item);
1866 }
1867
1868 eventType = wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT;
1869 wxConvertFromMSWListItem(GetHwnd(), event.m_item, item);
1870 event.m_itemIndex = event.m_item.m_itemId;
1871 }
1872 break;
1873
1874 case LVN_ENDLABELEDITA:
1875 case LVN_ENDLABELEDITW:
1876 {
1877 wxLV_ITEM item;
1878 if ( nmhdr->code == LVN_ENDLABELEDITA )
1879 {
1880 item.Init(((LV_DISPINFOA *)lParam)->item);
1881 }
1882 else // LVN_ENDLABELEDITW
1883 {
1884 item.Init(((LV_DISPINFOW *)lParam)->item);
1885 }
1886
1887 // was editing cancelled?
1888 const LV_ITEM& lvi = (LV_ITEM)item;
1889 if ( !lvi.pszText || lvi.iItem == -1 )
1890 {
1891 // don't keep a stale wxTextCtrl around
1892 if ( m_textCtrl )
1893 {
1894 // EDIT control will be deleted by the list control itself so
1895 // prevent us from deleting it as well
1896 m_textCtrl->UnsubclassWin();
1897 m_textCtrl->SetHWND(0);
1898 delete m_textCtrl;
1899 m_textCtrl = NULL;
1900 }
1901
1902 event.SetEditCanceled(true);
1903 }
1904
1905 eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT;
1906 wxConvertFromMSWListItem(NULL, event.m_item, item);
1907 event.m_itemIndex = event.m_item.m_itemId;
1908 }
1909 break;
1910
1911 case LVN_COLUMNCLICK:
1912 eventType = wxEVT_COMMAND_LIST_COL_CLICK;
1913 event.m_itemIndex = -1;
1914 event.m_col = nmLV->iSubItem;
1915 break;
1916
1917 case LVN_DELETEALLITEMS:
1918 m_count = 0;
1919 eventType = wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS;
1920 event.m_itemIndex = -1;
1921 break;
1922
1923 case LVN_DELETEITEM:
1924 if (m_count == 0)
1925 // this should be prevented by the post-processing code below,
1926 // but "just in case"
1927 return false;
1928
1929 eventType = wxEVT_COMMAND_LIST_DELETE_ITEM;
1930 event.m_itemIndex = iItem;
1931 // delete the assoicated internal data
1932 wxDeleteInternalData(this, iItem);
1933 break;
1934
1935 #if WXWIN_COMPATIBILITY_2_4
1936 case LVN_SETDISPINFO:
1937 {
1938 eventType = wxEVT_COMMAND_LIST_SET_INFO;
1939 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1940 wxConvertFromMSWListItem(GetHwnd(), event.m_item, info->item);
1941 }
1942 break;
1943 #endif
1944
1945 case LVN_INSERTITEM:
1946 eventType = wxEVT_COMMAND_LIST_INSERT_ITEM;
1947 event.m_itemIndex = iItem;
1948 break;
1949
1950 case LVN_ITEMCHANGED:
1951 // we translate this catch all message into more interesting
1952 // (and more easy to process) wxWidgets events
1953
1954 // first of all, we deal with the state change events only and
1955 // only for valid items (item == -1 for the virtual list
1956 // control)
1957 if ( nmLV->uChanged & LVIF_STATE && iItem != -1 )
1958 {
1959 // temp vars for readability
1960 const UINT stOld = nmLV->uOldState;
1961 const UINT stNew = nmLV->uNewState;
1962
1963 event.m_item.SetId(iItem);
1964 event.m_item.SetMask(wxLIST_MASK_TEXT |
1965 wxLIST_MASK_IMAGE |
1966 wxLIST_MASK_DATA);
1967 GetItem(event.m_item);
1968
1969 // has the focus changed?
1970 if ( !(stOld & LVIS_FOCUSED) && (stNew & LVIS_FOCUSED) )
1971 {
1972 eventType = wxEVT_COMMAND_LIST_ITEM_FOCUSED;
1973 event.m_itemIndex = iItem;
1974 }
1975
1976 if ( (stNew & LVIS_SELECTED) != (stOld & LVIS_SELECTED) )
1977 {
1978 if ( eventType != wxEVT_NULL )
1979 {
1980 // focus and selection have both changed: send the
1981 // focus event from here and the selection one
1982 // below
1983 event.SetEventType(eventType);
1984 (void)GetEventHandler()->ProcessEvent(event);
1985 }
1986 else // no focus event to send
1987 {
1988 // then need to set m_itemIndex as it wasn't done
1989 // above
1990 event.m_itemIndex = iItem;
1991 }
1992
1993 eventType = stNew & LVIS_SELECTED
1994 ? wxEVT_COMMAND_LIST_ITEM_SELECTED
1995 : wxEVT_COMMAND_LIST_ITEM_DESELECTED;
1996 }
1997 }
1998
1999 if ( eventType == wxEVT_NULL )
2000 {
2001 // not an interesting event for us
2002 return false;
2003 }
2004
2005 break;
2006
2007 case LVN_KEYDOWN:
2008 {
2009 LV_KEYDOWN *info = (LV_KEYDOWN *)lParam;
2010 WORD wVKey = info->wVKey;
2011
2012 // get the current selection
2013 long lItem = GetNextItem(-1,
2014 wxLIST_NEXT_ALL,
2015 wxLIST_STATE_SELECTED);
2016
2017 // <Enter> or <Space> activate the selected item if any (but
2018 // not with Shift and/or Ctrl as then they have a predefined
2019 // meaning for the list view)
2020 if ( lItem != -1 &&
2021 (wVKey == VK_RETURN || wVKey == VK_SPACE) &&
2022 !(wxIsShiftDown() || wxIsCtrlDown()) )
2023 {
2024 eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
2025 }
2026 else
2027 {
2028 eventType = wxEVT_COMMAND_LIST_KEY_DOWN;
2029
2030 // wxCharCodeMSWToWX() returns 0 if the key is an ASCII
2031 // value which should be used as is
2032 int code = wxCharCodeMSWToWX(wVKey);
2033 event.m_code = code ? code : wVKey;
2034 }
2035
2036 event.m_itemIndex =
2037 event.m_item.m_itemId = lItem;
2038
2039 if ( lItem != -1 )
2040 {
2041 // fill the other fields too
2042 event.m_item.m_text = GetItemText(lItem);
2043 event.m_item.m_data = GetItemData(lItem);
2044 }
2045 }
2046 break;
2047
2048 case NM_DBLCLK:
2049 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
2050 // anything else
2051 if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
2052 {
2053 return true;
2054 }
2055
2056 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
2057 // if it happened on an item (and not on empty place)
2058 if ( iItem == -1 )
2059 {
2060 // not on item
2061 return false;
2062 }
2063
2064 eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
2065 event.m_itemIndex = iItem;
2066 event.m_item.m_text = GetItemText(iItem);
2067 event.m_item.m_data = GetItemData(iItem);
2068 break;
2069
2070 #if defined(__WXWINCE__) && !defined(__HANDHELDPC__) && _WIN32_WCE < 400
2071 case GN_CONTEXTMENU:
2072 #endif //__WXWINCE__
2073 case NM_RCLICK:
2074 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
2075 // don't do anything else
2076 if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
2077 {
2078 return true;
2079 }
2080
2081 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
2082 LV_HITTESTINFO lvhti;
2083 wxZeroMemory(lvhti);
2084
2085 #if defined(__WXWINCE__) && !defined(__HANDHELDPC__) && _WIN32_WCE < 400
2086 if(nmhdr->code == GN_CONTEXTMENU) {
2087 lvhti.pt = ((NMRGINFO*)nmhdr)->ptAction;
2088 } else
2089 #endif //__WXWINCE__
2090 ::GetCursorPos(&(lvhti.pt));
2091 ::ScreenToClient(GetHwnd(),&(lvhti.pt));
2092 if ( ListView_HitTest(GetHwnd(),&lvhti) != -1 )
2093 {
2094 if ( lvhti.flags & LVHT_ONITEM )
2095 {
2096 eventType = wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK;
2097 event.m_itemIndex = lvhti.iItem;
2098 event.m_pointDrag.x = lvhti.pt.x;
2099 event.m_pointDrag.y = lvhti.pt.y;
2100 }
2101 }
2102 break;
2103
2104 #ifdef NM_CUSTOMDRAW
2105 case NM_CUSTOMDRAW:
2106 *result = OnCustomDraw(lParam);
2107
2108 return true;
2109 #endif // _WIN32_IE >= 0x300
2110
2111 case LVN_ODCACHEHINT:
2112 {
2113 const NM_CACHEHINT *cacheHint = (NM_CACHEHINT *)lParam;
2114
2115 eventType = wxEVT_COMMAND_LIST_CACHE_HINT;
2116
2117 // we get some really stupid cache hints like ones for
2118 // items in range 0..0 for an empty control or, after
2119 // deleting an item, for items in invalid range -- filter
2120 // this garbage out
2121 if ( cacheHint->iFrom > cacheHint->iTo )
2122 return false;
2123
2124 event.m_oldItemIndex = cacheHint->iFrom;
2125
2126 const long iMax = GetItemCount();
2127 event.m_itemIndex = cacheHint->iTo < iMax ? cacheHint->iTo
2128 : iMax - 1;
2129 }
2130 break;
2131
2132 case LVN_GETDISPINFO:
2133 if ( IsVirtual() )
2134 {
2135 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
2136
2137 LV_ITEM& lvi = info->item;
2138 long item = lvi.iItem;
2139
2140 if ( lvi.mask & LVIF_TEXT )
2141 {
2142 wxString text = OnGetItemText(item, lvi.iSubItem);
2143 wxStrncpy(lvi.pszText, text, lvi.cchTextMax);
2144 }
2145
2146 // see comment at the end of wxListCtrl::GetColumn()
2147 #ifdef NM_CUSTOMDRAW
2148 if ( lvi.mask & LVIF_IMAGE )
2149 {
2150 lvi.iImage = OnGetItemImage(item);
2151 }
2152 #endif // NM_CUSTOMDRAW
2153
2154 // a little dose of healthy paranoia: as we never use
2155 // LVM_SETCALLBACKMASK we're not supposed to get these ones
2156 wxASSERT_MSG( !(lvi.mask & LVIF_STATE),
2157 _T("we don't support state callbacks yet!") );
2158
2159 return true;
2160 }
2161 // fall through
2162
2163 default:
2164 return wxControl::MSWOnNotify(idCtrl, lParam, result);
2165 }
2166 }
2167 else
2168 {
2169 // where did this one come from?
2170 return false;
2171 }
2172
2173 // process the event
2174 // -----------------
2175
2176 event.SetEventType(eventType);
2177
2178 bool processed = GetEventHandler()->ProcessEvent(event);
2179
2180 // post processing
2181 // ---------------
2182 switch ( nmhdr->code )
2183 {
2184 case LVN_DELETEALLITEMS:
2185 // always return true to suppress all additional LVN_DELETEITEM
2186 // notifications - this makes deleting all items from a list ctrl
2187 // much faster
2188 *result = TRUE;
2189
2190 // also, we may free all user data now (couldn't do it before as
2191 // the user should have access to it in OnDeleteAllItems() handler)
2192 FreeAllInternalData();
2193 return true;
2194
2195 case LVN_ENDLABELEDITA:
2196 case LVN_ENDLABELEDITW:
2197 // logic here is inversed compared to all the other messages
2198 *result = event.IsAllowed();
2199
2200 // don't keep a stale wxTextCtrl around
2201 if ( m_textCtrl )
2202 {
2203 // EDIT control will be deleted by the list control itself so
2204 // prevent us from deleting it as well
2205 m_textCtrl->UnsubclassWin();
2206 m_textCtrl->SetHWND(0);
2207 delete m_textCtrl;
2208 m_textCtrl = NULL;
2209 }
2210
2211 return true;
2212 }
2213
2214 if ( processed )
2215 *result = !event.IsAllowed();
2216
2217 return processed;
2218 }
2219
2220 // see comment at the end of wxListCtrl::GetColumn()
2221 #ifdef NM_CUSTOMDRAW // _WIN32_IE >= 0x0300
2222
2223 WXLPARAM wxListCtrl::OnCustomDraw(WXLPARAM lParam)
2224 {
2225 LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
2226 NMCUSTOMDRAW& nmcd = lplvcd->nmcd;
2227 switch ( nmcd.dwDrawStage )
2228 {
2229 case CDDS_PREPAINT:
2230 // if we've got any items with non standard attributes,
2231 // notify us before painting each item
2232 //
2233 // for virtual controls, always suppose that we have attributes as
2234 // there is no way to check for this
2235 return IsVirtual() || m_hasAnyAttr ? CDRF_NOTIFYITEMDRAW
2236 : CDRF_DODEFAULT;
2237
2238 case CDDS_ITEMPREPAINT:
2239 {
2240 size_t item = (size_t)nmcd.dwItemSpec;
2241 if ( item >= (size_t)GetItemCount() )
2242 {
2243 // we get this message with item == 0 for an empty control,
2244 // we must ignore it as calling OnGetItemAttr() would be
2245 // wrong
2246 return CDRF_DODEFAULT;
2247 }
2248
2249 wxListItemAttr *attr =
2250 IsVirtual() ? OnGetItemAttr(item)
2251 : wxGetInternalDataAttr(this, item);
2252
2253 if ( !attr )
2254 {
2255 // nothing to do for this item
2256 return CDRF_DODEFAULT;
2257 }
2258
2259 HFONT hFont;
2260 wxColour colText, colBack;
2261 if ( attr->HasFont() )
2262 {
2263 wxFont font = attr->GetFont();
2264 hFont = (HFONT)font.GetResourceHandle();
2265 }
2266 else
2267 {
2268 hFont = 0;
2269 }
2270
2271 if ( attr->HasTextColour() )
2272 {
2273 colText = attr->GetTextColour();
2274 }
2275 else
2276 {
2277 colText = GetTextColour();
2278 }
2279
2280 if ( attr->HasBackgroundColour() )
2281 {
2282 colBack = attr->GetBackgroundColour();
2283 }
2284 else
2285 {
2286 colBack = GetBackgroundColour();
2287 }
2288
2289 lplvcd->clrText = wxColourToRGB(colText);
2290 lplvcd->clrTextBk = wxColourToRGB(colBack);
2291
2292 // note that if we wanted to set colours for
2293 // individual columns (subitems), we would have
2294 // returned CDRF_NOTIFYSUBITEMREDRAW from here
2295 if ( hFont )
2296 {
2297 ::SelectObject(nmcd.hdc, hFont);
2298
2299 return CDRF_NEWFONT;
2300 }
2301 }
2302 // fall through to return CDRF_DODEFAULT
2303
2304 default:
2305 return CDRF_DODEFAULT;
2306 }
2307 }
2308
2309 #endif // NM_CUSTOMDRAW supported
2310
2311 // Necessary for drawing hrules and vrules, if specified
2312 void wxListCtrl::OnPaint(wxPaintEvent& event)
2313 {
2314 wxPaintDC dc(this);
2315
2316 wxControl::OnPaint(event);
2317
2318 // Reset the device origin since it may have been set
2319 dc.SetDeviceOrigin(0, 0);
2320
2321 bool drawHRules = HasFlag(wxLC_HRULES);
2322 bool drawVRules = HasFlag(wxLC_VRULES);
2323
2324 if (!InReportView() || !drawHRules && !drawVRules)
2325 return;
2326
2327 wxPen pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
2328 dc.SetPen(pen);
2329 dc.SetBrush(* wxTRANSPARENT_BRUSH);
2330
2331 wxSize clientSize = GetClientSize();
2332 wxRect itemRect;
2333
2334 int itemCount = GetItemCount();
2335 int i;
2336 if (drawHRules)
2337 {
2338 long top = GetTopItem();
2339 for (i = top; i < top + GetCountPerPage() + 1; i++)
2340 {
2341 if (GetItemRect(i, itemRect))
2342 {
2343 int cy = itemRect.GetTop();
2344 if (i != 0) // Don't draw the first one
2345 {
2346 dc.DrawLine(0, cy, clientSize.x, cy);
2347 }
2348 // Draw last line
2349 if (i == itemCount - 1)
2350 {
2351 cy = itemRect.GetBottom();
2352 dc.DrawLine(0, cy, clientSize.x, cy);
2353 }
2354 }
2355 }
2356 }
2357 i = itemCount - 1;
2358 if (drawVRules && (i > -1))
2359 {
2360 wxRect firstItemRect;
2361 GetItemRect(0, firstItemRect);
2362
2363 if (GetItemRect(i, itemRect))
2364 {
2365 int col;
2366 int x = itemRect.GetX();
2367 for (col = 0; col < GetColumnCount(); col++)
2368 {
2369 int colWidth = GetColumnWidth(col);
2370 x += colWidth ;
2371 dc.DrawLine(x-1, firstItemRect.GetY() - 2, x-1, itemRect.GetBottom());
2372 }
2373 }
2374 }
2375 }
2376
2377 // ----------------------------------------------------------------------------
2378 // virtual list controls
2379 // ----------------------------------------------------------------------------
2380
2381 wxString wxListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const
2382 {
2383 // this is a pure virtual function, in fact - which is not really pure
2384 // because the controls which are not virtual don't need to implement it
2385 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2386
2387 return wxEmptyString;
2388 }
2389
2390 int wxListCtrl::OnGetItemImage(long WXUNUSED(item)) const
2391 {
2392 // same as above
2393 wxFAIL_MSG( _T("wxListCtrl::OnGetItemImage not supposed to be called") );
2394
2395 return -1;
2396 }
2397
2398 wxListItemAttr *wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)) const
2399 {
2400 wxASSERT_MSG( item >= 0 && item < GetItemCount(),
2401 _T("invalid item index in OnGetItemAttr()") );
2402
2403 // no attributes by default
2404 return NULL;
2405 }
2406
2407 void wxListCtrl::SetItemCount(long count)
2408 {
2409 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2410
2411 if ( !::SendMessage(GetHwnd(), LVM_SETITEMCOUNT, (WPARAM)count,
2412 LVSICF_NOSCROLL | LVSICF_NOINVALIDATEALL) )
2413 {
2414 wxLogLastError(_T("ListView_SetItemCount"));
2415 }
2416 m_count = count;
2417 wxASSERT_MSG( m_count == ListView_GetItemCount(GetHwnd()),
2418 wxT("m_count should match ListView_GetItemCount"));
2419 }
2420
2421 void wxListCtrl::RefreshItem(long item)
2422 {
2423 // strangely enough, ListView_Update() results in much more flicker here
2424 // than a dumb Refresh() -- why?
2425 #if 0
2426 if ( !ListView_Update(GetHwnd(), item) )
2427 {
2428 wxLogLastError(_T("ListView_Update"));
2429 }
2430 #else // 1
2431 wxRect rect;
2432 GetItemRect(item, rect);
2433 RefreshRect(rect);
2434 #endif // 0/1
2435 }
2436
2437 void wxListCtrl::RefreshItems(long itemFrom, long itemTo)
2438 {
2439 wxRect rect1, rect2;
2440 GetItemRect(itemFrom, rect1);
2441 GetItemRect(itemTo, rect2);
2442
2443 wxRect rect = rect1;
2444 rect.height = rect2.GetBottom() - rect1.GetTop();
2445
2446 RefreshRect(rect);
2447 }
2448
2449 // ----------------------------------------------------------------------------
2450 // internal data stuff
2451 // ----------------------------------------------------------------------------
2452
2453 static wxListItemInternalData *wxGetInternalData(HWND hwnd, long itemId)
2454 {
2455 LV_ITEM it;
2456 it.mask = LVIF_PARAM;
2457 it.iItem = itemId;
2458
2459 if ( !ListView_GetItem(hwnd, &it) )
2460 return NULL;
2461
2462 return (wxListItemInternalData *) it.lParam;
2463 };
2464
2465 static
2466 wxListItemInternalData *wxGetInternalData(const wxListCtrl *ctl, long itemId)
2467 {
2468 return wxGetInternalData(GetHwndOf(ctl), itemId);
2469 };
2470
2471 static wxListItemAttr *wxGetInternalDataAttr(wxListCtrl *ctl, long itemId)
2472 {
2473 wxListItemInternalData *data = wxGetInternalData(ctl, itemId);
2474
2475 return data ? data->attr : NULL;
2476 };
2477
2478 static void wxDeleteInternalData(wxListCtrl* ctl, long itemId)
2479 {
2480 wxListItemInternalData *data = wxGetInternalData(ctl, itemId);
2481 if (data)
2482 {
2483 LV_ITEM item;
2484 memset(&item, 0, sizeof(item));
2485 item.iItem = itemId;
2486 item.mask = LVIF_PARAM;
2487 item.lParam = (LPARAM) 0;
2488 ListView_SetItem((HWND)ctl->GetHWND(), &item);
2489 delete data;
2490 }
2491 }
2492
2493 // ----------------------------------------------------------------------------
2494 // wxWin <-> MSW items conversions
2495 // ----------------------------------------------------------------------------
2496
2497 static void wxConvertFromMSWListItem(HWND hwndListCtrl,
2498 wxListItem& info,
2499 LV_ITEM& lvItem)
2500 {
2501 wxListItemInternalData *internaldata =
2502 (wxListItemInternalData *) lvItem.lParam;
2503
2504 if (internaldata)
2505 info.m_data = internaldata->lParam;
2506
2507 info.m_mask = 0;
2508 info.m_state = 0;
2509 info.m_stateMask = 0;
2510 info.m_itemId = lvItem.iItem;
2511
2512 long oldMask = lvItem.mask;
2513
2514 bool needText = false;
2515 if (hwndListCtrl != 0)
2516 {
2517 if ( lvItem.mask & LVIF_TEXT )
2518 needText = false;
2519 else
2520 needText = true;
2521
2522 if ( needText )
2523 {
2524 lvItem.pszText = new wxChar[513];
2525 lvItem.cchTextMax = 512;
2526 }
2527 lvItem.mask |= LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
2528 ::SendMessage(hwndListCtrl, LVM_GETITEM, 0, (LPARAM)& lvItem);
2529 }
2530
2531 if ( lvItem.mask & LVIF_STATE )
2532 {
2533 info.m_mask |= wxLIST_MASK_STATE;
2534
2535 if ( lvItem.stateMask & LVIS_CUT)
2536 {
2537 info.m_stateMask |= wxLIST_STATE_CUT;
2538 if ( lvItem.state & LVIS_CUT )
2539 info.m_state |= wxLIST_STATE_CUT;
2540 }
2541 if ( lvItem.stateMask & LVIS_DROPHILITED)
2542 {
2543 info.m_stateMask |= wxLIST_STATE_DROPHILITED;
2544 if ( lvItem.state & LVIS_DROPHILITED )
2545 info.m_state |= wxLIST_STATE_DROPHILITED;
2546 }
2547 if ( lvItem.stateMask & LVIS_FOCUSED)
2548 {
2549 info.m_stateMask |= wxLIST_STATE_FOCUSED;
2550 if ( lvItem.state & LVIS_FOCUSED )
2551 info.m_state |= wxLIST_STATE_FOCUSED;
2552 }
2553 if ( lvItem.stateMask & LVIS_SELECTED)
2554 {
2555 info.m_stateMask |= wxLIST_STATE_SELECTED;
2556 if ( lvItem.state & LVIS_SELECTED )
2557 info.m_state |= wxLIST_STATE_SELECTED;
2558 }
2559 }
2560
2561 if ( lvItem.mask & LVIF_TEXT )
2562 {
2563 info.m_mask |= wxLIST_MASK_TEXT;
2564 info.m_text = lvItem.pszText;
2565 }
2566 if ( lvItem.mask & LVIF_IMAGE )
2567 {
2568 info.m_mask |= wxLIST_MASK_IMAGE;
2569 info.m_image = lvItem.iImage;
2570 }
2571 if ( lvItem.mask & LVIF_PARAM )
2572 info.m_mask |= wxLIST_MASK_DATA;
2573 if ( lvItem.mask & LVIF_DI_SETITEM )
2574 info.m_mask |= wxLIST_SET_ITEM;
2575 info.m_col = lvItem.iSubItem;
2576
2577 if (needText)
2578 {
2579 if (lvItem.pszText)
2580 delete[] lvItem.pszText;
2581 }
2582 lvItem.mask = oldMask;
2583 }
2584
2585 static void wxConvertToMSWFlags(long state, long stateMask, LV_ITEM& lvItem)
2586 {
2587 if (stateMask & wxLIST_STATE_CUT)
2588 {
2589 lvItem.stateMask |= LVIS_CUT;
2590 if (state & wxLIST_STATE_CUT)
2591 lvItem.state |= LVIS_CUT;
2592 }
2593 if (stateMask & wxLIST_STATE_DROPHILITED)
2594 {
2595 lvItem.stateMask |= LVIS_DROPHILITED;
2596 if (state & wxLIST_STATE_DROPHILITED)
2597 lvItem.state |= LVIS_DROPHILITED;
2598 }
2599 if (stateMask & wxLIST_STATE_FOCUSED)
2600 {
2601 lvItem.stateMask |= LVIS_FOCUSED;
2602 if (state & wxLIST_STATE_FOCUSED)
2603 lvItem.state |= LVIS_FOCUSED;
2604 }
2605 if (stateMask & wxLIST_STATE_SELECTED)
2606 {
2607 lvItem.stateMask |= LVIS_SELECTED;
2608 if (state & wxLIST_STATE_SELECTED)
2609 lvItem.state |= LVIS_SELECTED;
2610 }
2611 }
2612
2613 static void wxConvertToMSWListItem(const wxListCtrl *ctrl,
2614 const wxListItem& info,
2615 LV_ITEM& lvItem)
2616 {
2617 lvItem.iItem = (int) info.m_itemId;
2618
2619 lvItem.iImage = info.m_image;
2620 lvItem.stateMask = 0;
2621 lvItem.state = 0;
2622 lvItem.mask = 0;
2623 lvItem.iSubItem = info.m_col;
2624
2625 if (info.m_mask & wxLIST_MASK_STATE)
2626 {
2627 lvItem.mask |= LVIF_STATE;
2628
2629 wxConvertToMSWFlags(info.m_state, info.m_stateMask, lvItem);
2630 }
2631
2632 if (info.m_mask & wxLIST_MASK_TEXT)
2633 {
2634 lvItem.mask |= LVIF_TEXT;
2635 if ( ctrl->HasFlag(wxLC_USER_TEXT) )
2636 {
2637 lvItem.pszText = LPSTR_TEXTCALLBACK;
2638 }
2639 else
2640 {
2641 // pszText is not const, hence the cast
2642 lvItem.pszText = (wxChar *)info.m_text.c_str();
2643 if ( lvItem.pszText )
2644 lvItem.cchTextMax = info.m_text.Length();
2645 else
2646 lvItem.cchTextMax = 0;
2647 }
2648 }
2649 if (info.m_mask & wxLIST_MASK_IMAGE)
2650 lvItem.mask |= LVIF_IMAGE;
2651 }
2652
2653 static void wxConvertToMSWListCol(int WXUNUSED(col), const wxListItem& item,
2654 LV_COLUMN& lvCol)
2655 {
2656 wxZeroMemory(lvCol);
2657
2658 if ( item.m_mask & wxLIST_MASK_TEXT )
2659 {
2660 lvCol.mask |= LVCF_TEXT;
2661 lvCol.pszText = (wxChar *)item.m_text.c_str(); // cast is safe
2662 }
2663
2664 if ( item.m_mask & wxLIST_MASK_FORMAT )
2665 {
2666 lvCol.mask |= LVCF_FMT;
2667
2668 if ( item.m_format == wxLIST_FORMAT_LEFT )
2669 lvCol.fmt = LVCFMT_LEFT;
2670 else if ( item.m_format == wxLIST_FORMAT_RIGHT )
2671 lvCol.fmt = LVCFMT_RIGHT;
2672 else if ( item.m_format == wxLIST_FORMAT_CENTRE )
2673 lvCol.fmt = LVCFMT_CENTER;
2674 }
2675
2676 if ( item.m_mask & wxLIST_MASK_WIDTH )
2677 {
2678 lvCol.mask |= LVCF_WIDTH;
2679 if ( item.m_width == wxLIST_AUTOSIZE)
2680 lvCol.cx = LVSCW_AUTOSIZE;
2681 else if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER)
2682 lvCol.cx = LVSCW_AUTOSIZE_USEHEADER;
2683 else
2684 lvCol.cx = item.m_width;
2685 }
2686
2687 // see comment at the end of wxListCtrl::GetColumn()
2688 #ifdef NM_CUSTOMDRAW // _WIN32_IE >= 0x0300
2689 if ( item.m_mask & wxLIST_MASK_IMAGE )
2690 {
2691 if ( wxTheApp->GetComCtl32Version() >= 470 )
2692 {
2693 lvCol.mask |= LVCF_IMAGE | LVCF_FMT;
2694
2695 // we use LVCFMT_BITMAP_ON_RIGHT because thei mages on the right
2696 // seem to be generally nicer than on the left and the generic
2697 // version only draws them on the right (we don't have a flag to
2698 // specify the image location anyhow)
2699 //
2700 // we don't use LVCFMT_COL_HAS_IMAGES because it doesn't seem to
2701 // make any difference in my tests -- but maybe we should?
2702 lvCol.fmt |= LVCFMT_BITMAP_ON_RIGHT | LVCFMT_IMAGE;
2703
2704 lvCol.iImage = item.m_image;
2705 }
2706 //else: it doesn't support item images anyhow
2707 }
2708 #endif // _WIN32_IE >= 0x0300
2709 }
2710
2711 #endif // wxUSE_LISTCTRL
2712