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