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