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