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