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