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