]> git.saurik.com Git - wxWidgets.git/blob - src/msw/listctrl.cpp
use LVM_SETITEMSTATE instead of LVM_SETITEM for virtual controls
[wxWidgets.git] / src / msw / listctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "listctrl.h"
22 #pragma implementation "listctrlbase.h"
23 #endif
24
25 // For compilers that support precompilation, includes "wx.h".
26 #include "wx/wxprec.h"
27
28 #ifdef __BORLANDC__
29 #pragma hdrstop
30 #endif
31
32 #if wxUSE_LISTCTRL && defined(__WIN95__)
33
34 #ifndef WX_PRECOMP
35 #include "wx/app.h"
36 #include "wx/intl.h"
37 #include "wx/log.h"
38 #include "wx/settings.h"
39 #endif
40
41 #include "wx/textctrl.h"
42 #include "wx/imaglist.h"
43 #include "wx/listctrl.h"
44 #include "wx/dcclient.h"
45
46 #include "wx/msw/private.h"
47
48 #if ((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__))
49 #include "wx/msw/gnuwin32/extra.h"
50 #else
51 #include <commctrl.h>
52 #endif
53
54 #ifndef LVHT_ONITEM
55 #define LVHT_ONITEM \
56 (LVHT_ONITEMICON | LVHT_ONITEMLABEL | LVHT_ONITEMSTATEICON)
57 #endif
58
59 #ifndef LVM_SETEXTENDEDLISTVIEWSTYLE
60 #define LVM_SETEXTENDEDLISTVIEWSTYLE (0x1000 + 54)
61 #endif
62
63 #ifndef LVS_EX_FULLROWSELECT
64 #define LVS_EX_FULLROWSELECT 0x00000020
65 #endif
66
67 #ifndef LVS_OWNERDATA
68 #define LVS_OWNERDATA 0x1000
69 #endif
70
71 // ----------------------------------------------------------------------------
72 // private functions
73 // ----------------------------------------------------------------------------
74
75 // convert our state and mask flags to LV_ITEM constants
76 static void wxConvertToMSWFlags(long state, long mask, LV_ITEM& lvItem);
77
78 // convert wxListItem to LV_ITEM
79 static void wxConvertToMSWListItem(const wxListCtrl *ctrl,
80 const wxListItem& info, LV_ITEM& lvItem);
81
82 // convert LV_ITEM to wxListItem
83 static void wxConvertFromMSWListItem(HWND hwndListCtrl,
84 wxListItem& info,
85 /* const */ LV_ITEM& lvItem);
86
87 // ----------------------------------------------------------------------------
88 // events
89 // ----------------------------------------------------------------------------
90
91 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG)
92 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG)
93 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT)
94 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT)
95 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM)
96 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS)
97 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO)
98 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO)
99 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED)
100 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED)
101 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN)
102 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM)
103 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK)
104 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK)
105 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK)
106 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED)
107
108 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
109 IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
110
111 BEGIN_EVENT_TABLE(wxListCtrl, wxControl)
112 EVT_PAINT(wxListCtrl::OnPaint)
113 END_EVENT_TABLE()
114
115 // ============================================================================
116 // implementation
117 // ============================================================================
118
119 // ----------------------------------------------------------------------------
120 // wxListEvent
121 // ----------------------------------------------------------------------------
122
123 void wxListEvent::CopyObject(wxObject& object_dest) const
124 {
125 wxListEvent *obj = (wxListEvent *)&object_dest;
126
127 wxNotifyEvent::CopyObject(object_dest);
128
129 obj->m_code = m_code;
130 obj->m_itemIndex = m_itemIndex;
131 obj->m_oldItemIndex = m_oldItemIndex;
132 obj->m_col = m_col;
133 obj->m_cancelled = m_cancelled;
134 obj->m_pointDrag = m_pointDrag;
135 obj->m_item.m_mask = m_item.m_mask;
136 obj->m_item.m_itemId = m_item.m_itemId;
137 obj->m_item.m_col = m_item.m_col;
138 obj->m_item.m_state = m_item.m_state;
139 obj->m_item.m_stateMask = m_item.m_stateMask;
140 obj->m_item.m_text = m_item.m_text;
141 obj->m_item.m_image = m_item.m_image;
142 obj->m_item.m_data = m_item.m_data;
143 obj->m_item.m_format = m_item.m_format;
144 obj->m_item.m_width = m_item.m_width;
145
146 if ( m_item.HasAttributes() )
147 {
148 obj->m_item.SetTextColour(m_item.GetTextColour());
149 obj->m_item.SetBackgroundColour(m_item.GetBackgroundColour());
150 obj->m_item.SetFont(m_item.GetFont());
151 }
152 }
153
154 // ----------------------------------------------------------------------------
155 // wxListCtrl construction
156 // ----------------------------------------------------------------------------
157
158 void wxListCtrl::Init()
159 {
160 m_imageListNormal = NULL;
161 m_imageListSmall = NULL;
162 m_imageListState = NULL;
163 m_ownsImageListNormal = m_ownsImageListSmall = m_ownsImageListState = FALSE;
164 m_baseStyle = 0;
165 m_colCount = 0;
166 m_textCtrl = NULL;
167 m_hasAnyAttr = FALSE;
168 }
169
170 bool wxListCtrl::Create(wxWindow *parent,
171 wxWindowID id,
172 const wxPoint& pos,
173 const wxSize& size,
174 long style,
175 const wxValidator& validator,
176 const wxString& name)
177 {
178 #if wxUSE_VALIDATORS
179 SetValidator(validator);
180 #endif // wxUSE_VALIDATORS
181
182 SetName(name);
183
184 int x = pos.x;
185 int y = pos.y;
186 int width = size.x;
187 int height = size.y;
188
189 m_windowStyle = style;
190
191 SetParent(parent);
192
193 if (width <= 0)
194 width = 100;
195 if (height <= 0)
196 height = 30;
197 if (x < 0)
198 x = 0;
199 if (y < 0)
200 y = 0;
201
202 m_windowId = (id == -1) ? NewControlId() : id;
203
204 DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP |
205 LVS_SHAREIMAGELISTS | LVS_SHOWSELALWAYS;
206
207 if ( m_windowStyle & wxCLIP_SIBLINGS )
208 wstyle |= WS_CLIPSIBLINGS;
209
210 if ( wxStyleHasBorder(m_windowStyle) )
211 wstyle |= WS_BORDER;
212 m_baseStyle = wstyle;
213
214 if ( !DoCreateControl(x, y, width, height) )
215 return FALSE;
216
217 if (parent)
218 parent->AddChild(this);
219
220 return TRUE;
221 }
222
223 bool wxListCtrl::DoCreateControl(int x, int y, int w, int h)
224 {
225 DWORD wstyle = m_baseStyle;
226
227 bool want3D;
228 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D);
229
230 // Even with extended styles, need to combine with WS_BORDER
231 // for them to look right.
232 if ( want3D )
233 wstyle |= WS_BORDER;
234
235 long oldStyle = 0; // Dummy
236 wstyle |= ConvertToMSWStyle(oldStyle, m_windowStyle);
237
238 // Create the ListView control.
239 m_hWnd = (WXHWND)CreateWindowEx(exStyle,
240 WC_LISTVIEW,
241 wxT(""),
242 wstyle,
243 x, y, w, h,
244 GetWinHwnd(GetParent()),
245 (HMENU)m_windowId,
246 wxGetInstance(),
247 NULL);
248
249 if ( !m_hWnd )
250 {
251 wxLogError(_("Can't create list control window, check that comctl32.dll is installed."));
252
253 return FALSE;
254 }
255
256 // for comctl32.dll v 4.70+ we want to have this attribute because it's
257 // prettier (and also because wxGTK does it like this)
258 if ( (wstyle & LVS_REPORT) && wxTheApp->GetComCtl32Version() >= 470 )
259 {
260 ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE,
261 0, LVS_EX_FULLROWSELECT);
262 }
263
264 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW));
265 SetForegroundColour(GetParent()->GetForegroundColour());
266
267 SubclassWin(m_hWnd);
268
269 return TRUE;
270 }
271
272 void wxListCtrl::UpdateStyle()
273 {
274 if ( GetHWND() )
275 {
276 // The new window view style
277 long dummy;
278 DWORD dwStyleNew = ConvertToMSWStyle(dummy, m_windowStyle);
279 dwStyleNew |= m_baseStyle;
280
281 // Get the current window style.
282 DWORD dwStyleOld = ::GetWindowLong(GetHwnd(), GWL_STYLE);
283
284 // Only set the window style if the view bits have changed.
285 if ( dwStyleOld != dwStyleNew )
286 {
287 ::SetWindowLong(GetHwnd(), GWL_STYLE, dwStyleNew);
288 }
289 }
290 }
291
292 void wxListCtrl::FreeAllAttrs(bool dontRecreate)
293 {
294 if ( m_hasAnyAttr )
295 {
296 for ( wxNode *node = m_attrs.Next(); node; node = m_attrs.Next() )
297 {
298 delete (wxListItemAttr *)node->Data();
299 }
300
301 m_attrs.Destroy();
302 if ( !dontRecreate )
303 {
304 m_attrs.Create(wxKEY_INTEGER, 1000); // just as def ctor
305 }
306
307 m_hasAnyAttr = FALSE;
308 }
309 }
310
311 wxListCtrl::~wxListCtrl()
312 {
313 FreeAllAttrs(TRUE /* no need to recreate hash any more */);
314
315 if ( m_textCtrl )
316 {
317 m_textCtrl->SetHWND(0);
318 m_textCtrl->UnsubclassWin();
319 delete m_textCtrl;
320 m_textCtrl = NULL;
321 }
322
323 if (m_ownsImageListNormal) delete m_imageListNormal;
324 if (m_ownsImageListSmall) delete m_imageListSmall;
325 if (m_ownsImageListState) delete m_imageListState;
326 }
327
328 // ----------------------------------------------------------------------------
329 // set/get/change style
330 // ----------------------------------------------------------------------------
331
332 // Add or remove a single window style
333 void wxListCtrl::SetSingleStyle(long style, bool add)
334 {
335 long flag = GetWindowStyleFlag();
336
337 // Get rid of conflicting styles
338 if ( add )
339 {
340 if ( style & wxLC_MASK_TYPE)
341 flag = flag & ~wxLC_MASK_TYPE;
342 if ( style & wxLC_MASK_ALIGN )
343 flag = flag & ~wxLC_MASK_ALIGN;
344 if ( style & wxLC_MASK_SORT )
345 flag = flag & ~wxLC_MASK_SORT;
346 }
347
348 if ( flag & style )
349 {
350 if ( !add )
351 flag -= style;
352 }
353 else
354 {
355 if ( add )
356 {
357 flag |= style;
358 }
359 }
360
361 m_windowStyle = flag;
362
363 UpdateStyle();
364 }
365
366 // Set the whole window style
367 void wxListCtrl::SetWindowStyleFlag(long flag)
368 {
369 m_windowStyle = flag;
370
371 UpdateStyle();
372 }
373
374 // Can be just a single style, or a bitlist
375 long wxListCtrl::ConvertToMSWStyle(long& oldStyle, long style) const
376 {
377 long wstyle = 0;
378 if ( style & wxLC_ICON )
379 {
380 if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON )
381 oldStyle -= LVS_SMALLICON;
382 if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT )
383 oldStyle -= LVS_REPORT;
384 if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST )
385 oldStyle -= LVS_LIST;
386 wstyle |= LVS_ICON;
387 }
388
389 if ( style & wxLC_SMALL_ICON )
390 {
391 if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON )
392 oldStyle -= LVS_ICON;
393 if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT )
394 oldStyle -= LVS_REPORT;
395 if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST )
396 oldStyle -= LVS_LIST;
397 wstyle |= LVS_SMALLICON;
398 }
399
400 if ( style & wxLC_LIST )
401 {
402 if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON )
403 oldStyle -= LVS_ICON;
404 if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT )
405 oldStyle -= LVS_REPORT;
406 if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON )
407 oldStyle -= LVS_SMALLICON;
408 wstyle |= LVS_LIST;
409 }
410
411 if ( style & wxLC_REPORT )
412 {
413 if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON )
414 oldStyle -= LVS_ICON;
415 if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST )
416 oldStyle -= LVS_LIST;
417 if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON )
418 oldStyle -= LVS_SMALLICON;
419
420 wstyle |= LVS_REPORT;
421 }
422
423 if ( style & wxLC_ALIGN_LEFT )
424 {
425 if ( oldStyle & LVS_ALIGNTOP )
426 oldStyle -= LVS_ALIGNTOP;
427 wstyle |= LVS_ALIGNLEFT;
428 }
429
430 if ( style & wxLC_ALIGN_TOP )
431 {
432 if ( oldStyle & LVS_ALIGNLEFT )
433 oldStyle -= LVS_ALIGNLEFT;
434 wstyle |= LVS_ALIGNTOP;
435 }
436
437 if ( style & wxLC_AUTOARRANGE )
438 wstyle |= LVS_AUTOARRANGE;
439
440 if ( style & wxLC_NO_SORT_HEADER )
441 wstyle |= LVS_NOSORTHEADER;
442
443 if ( style & wxLC_NO_HEADER )
444 wstyle |= LVS_NOCOLUMNHEADER;
445
446 if ( style & wxLC_EDIT_LABELS )
447 wstyle |= LVS_EDITLABELS;
448
449 if ( style & wxLC_SINGLE_SEL )
450 wstyle |= LVS_SINGLESEL;
451
452 if ( style & wxLC_SORT_ASCENDING )
453 {
454 if ( oldStyle & LVS_SORTDESCENDING )
455 oldStyle -= LVS_SORTDESCENDING;
456 wstyle |= LVS_SORTASCENDING;
457 }
458
459 if ( style & wxLC_SORT_DESCENDING )
460 {
461 if ( oldStyle & LVS_SORTASCENDING )
462 oldStyle -= LVS_SORTASCENDING;
463 wstyle |= LVS_SORTDESCENDING;
464 }
465
466 if ( style & wxLC_VIRTUAL )
467 {
468 int ver = wxTheApp->GetComCtl32Version();
469 if ( ver < 470 )
470 {
471 wxLogWarning(_("Please install a newer version of comctl32.dll\n"
472 "(at least version 4.70 is required but you have "
473 "%d.%02d)\n"
474 "or this program won't operate correctly."),
475 ver / 100, ver % 100);
476 }
477
478 wstyle |= LVS_OWNERDATA;
479 }
480
481 return wstyle;
482 }
483
484 // ----------------------------------------------------------------------------
485 // accessors
486 // ----------------------------------------------------------------------------
487
488 // Sets the foreground, i.e. text, colour
489 bool wxListCtrl::SetForegroundColour(const wxColour& col)
490 {
491 if ( !wxWindow::SetForegroundColour(col) )
492 return FALSE;
493
494 ListView_SetTextColor(GetHwnd(), wxColourToRGB(col));
495
496 return TRUE;
497 }
498
499 // Sets the background colour
500 bool wxListCtrl::SetBackgroundColour(const wxColour& col)
501 {
502 if ( !wxWindow::SetBackgroundColour(col) )
503 return FALSE;
504
505 // we set the same colour for both the "empty" background and the items
506 // background
507 COLORREF color = wxColourToRGB(col);
508 ListView_SetBkColor(GetHwnd(), color);
509 ListView_SetTextBkColor(GetHwnd(), color);
510
511 return TRUE;
512 }
513
514 // Gets information about this column
515 bool wxListCtrl::GetColumn(int col, wxListItem& item) const
516 {
517 LV_COLUMN lvCol;
518 lvCol.mask = 0;
519 lvCol.fmt = 0;
520 lvCol.pszText = NULL;
521
522 if ( item.m_mask & wxLIST_MASK_TEXT )
523 {
524 lvCol.mask |= LVCF_TEXT;
525 lvCol.pszText = new wxChar[513];
526 lvCol.cchTextMax = 512;
527 }
528
529 bool success = (ListView_GetColumn(GetHwnd(), col, & lvCol) != 0);
530
531 // item.m_subItem = lvCol.iSubItem;
532 item.m_width = lvCol.cx;
533
534 if ( (item.m_mask & wxLIST_MASK_TEXT) && lvCol.pszText )
535 {
536 item.m_text = lvCol.pszText;
537 delete[] lvCol.pszText;
538 }
539
540 if ( item.m_mask & wxLIST_MASK_FORMAT )
541 {
542 if (lvCol.fmt == LVCFMT_LEFT)
543 item.m_format = wxLIST_FORMAT_LEFT;
544 else if (lvCol.fmt == LVCFMT_RIGHT)
545 item.m_format = wxLIST_FORMAT_RIGHT;
546 else if (lvCol.fmt == LVCFMT_CENTER)
547 item.m_format = wxLIST_FORMAT_CENTRE;
548 }
549
550 return success;
551 }
552
553 // Sets information about this column
554 bool wxListCtrl::SetColumn(int col, wxListItem& item)
555 {
556 LV_COLUMN lvCol;
557 lvCol.mask = 0;
558 lvCol.fmt = 0;
559 lvCol.pszText = NULL;
560
561 if ( item.m_mask & wxLIST_MASK_TEXT )
562 {
563 lvCol.mask |= LVCF_TEXT;
564 lvCol.pszText = WXSTRINGCAST item.m_text;
565 lvCol.cchTextMax = 0; // Ignored
566 }
567 if ( item.m_mask & wxLIST_MASK_FORMAT )
568 {
569 lvCol.mask |= LVCF_FMT;
570
571 if ( item.m_format == wxLIST_FORMAT_LEFT )
572 lvCol.fmt = LVCFMT_LEFT;
573 if ( item.m_format == wxLIST_FORMAT_RIGHT )
574 lvCol.fmt = LVCFMT_RIGHT;
575 if ( item.m_format == wxLIST_FORMAT_CENTRE )
576 lvCol.fmt = LVCFMT_CENTER;
577 }
578
579 if ( item.m_mask & wxLIST_MASK_WIDTH )
580 {
581 lvCol.mask |= LVCF_WIDTH;
582 lvCol.cx = item.m_width;
583
584 if ( lvCol.cx == wxLIST_AUTOSIZE)
585 lvCol.cx = LVSCW_AUTOSIZE;
586 else if ( lvCol.cx == wxLIST_AUTOSIZE_USEHEADER)
587 lvCol.cx = LVSCW_AUTOSIZE_USEHEADER;
588 }
589 lvCol.mask |= LVCF_SUBITEM;
590 lvCol.iSubItem = col;
591 return (ListView_SetColumn(GetHwnd(), col, & lvCol) != 0);
592 }
593
594 // Gets the column width
595 int wxListCtrl::GetColumnWidth(int col) const
596 {
597 return ListView_GetColumnWidth(GetHwnd(), col);
598 }
599
600 // Sets the column width
601 bool wxListCtrl::SetColumnWidth(int col, int width)
602 {
603 int col2 = col;
604 if ( m_windowStyle & wxLC_LIST )
605 col2 = -1;
606
607 int width2 = width;
608 if ( width2 == wxLIST_AUTOSIZE)
609 width2 = LVSCW_AUTOSIZE;
610 else if ( width2 == wxLIST_AUTOSIZE_USEHEADER)
611 width2 = LVSCW_AUTOSIZE_USEHEADER;
612
613 return (ListView_SetColumnWidth(GetHwnd(), col2, width2) != 0);
614 }
615
616 // Gets the number of items that can fit vertically in the
617 // visible area of the list control (list or report view)
618 // or the total number of items in the list control (icon
619 // or small icon view)
620 int wxListCtrl::GetCountPerPage() const
621 {
622 return ListView_GetCountPerPage(GetHwnd());
623 }
624
625 // Gets the edit control for editing labels.
626 wxTextCtrl* wxListCtrl::GetEditControl() const
627 {
628 return m_textCtrl;
629 }
630
631 // Gets information about the item
632 bool wxListCtrl::GetItem(wxListItem& info) const
633 {
634 LV_ITEM lvItem;
635 wxZeroMemory(lvItem);
636
637 lvItem.iItem = info.m_itemId;
638 lvItem.iSubItem = info.m_col;
639
640 if ( info.m_mask & wxLIST_MASK_TEXT )
641 {
642 lvItem.mask |= LVIF_TEXT;
643 lvItem.pszText = new wxChar[513];
644 lvItem.cchTextMax = 512;
645 }
646 else
647 {
648 lvItem.pszText = NULL;
649 }
650
651 if (info.m_mask & wxLIST_MASK_DATA)
652 lvItem.mask |= LVIF_PARAM;
653
654 if (info.m_mask & wxLIST_MASK_IMAGE)
655 lvItem.mask |= LVIF_IMAGE;
656
657 if ( info.m_mask & wxLIST_MASK_STATE )
658 {
659 lvItem.mask |= LVIF_STATE;
660 // the other bits are hardly interesting anyhow
661 lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
662 }
663
664 bool success = ListView_GetItem((HWND)GetHWND(), &lvItem) != 0;
665 if ( !success )
666 {
667 wxLogError(_("Couldn't retrieve information about list control item %d."),
668 lvItem.iItem);
669 }
670 else
671 {
672 wxConvertFromMSWListItem(GetHwnd(), info, lvItem);
673 }
674
675 if (lvItem.pszText)
676 delete[] lvItem.pszText;
677
678 return success;
679 }
680
681 // Sets information about the item
682 bool wxListCtrl::SetItem(wxListItem& info)
683 {
684 LV_ITEM item;
685 wxConvertToMSWListItem(this, info, item);
686
687 item.cchTextMax = 0;
688 if ( !ListView_SetItem(GetHwnd(), &item) )
689 {
690 wxLogDebug(_T("ListView_SetItem() failed"));
691
692 return FALSE;
693 }
694
695 // we need to update the item immediately to show the new image
696 bool updateNow = (info.m_mask & wxLIST_MASK_IMAGE) != 0;
697
698 // check whether it has any custom attributes
699 if ( info.HasAttributes() )
700 {
701 wxListItemAttr *attr = (wxListItemAttr *)m_attrs.Get(item.iItem);
702
703 if ( attr == NULL )
704 m_attrs.Put(item.iItem, (wxObject *)new wxListItemAttr(*info.GetAttributes()));
705 else
706 *attr = *info.GetAttributes();
707
708 m_hasAnyAttr = TRUE;
709
710 // if the colour has changed, we must redraw the item
711 updateNow = TRUE;
712 }
713
714 if ( updateNow )
715 {
716 // we need this to make the change visible right now
717 ListView_Update(GetHwnd(), item.iItem);
718 }
719
720 return TRUE;
721 }
722
723 long wxListCtrl::SetItem(long index, int col, const wxString& label, int imageId)
724 {
725 wxListItem info;
726 info.m_text = label;
727 info.m_mask = wxLIST_MASK_TEXT;
728 info.m_itemId = index;
729 info.m_col = col;
730 if ( imageId > -1 )
731 {
732 info.m_image = imageId;
733 info.m_mask |= wxLIST_MASK_IMAGE;
734 }
735 return SetItem(info);
736 }
737
738
739 // Gets the item state
740 int wxListCtrl::GetItemState(long item, long stateMask) const
741 {
742 wxListItem info;
743
744 info.m_mask = wxLIST_MASK_STATE;
745 info.m_stateMask = stateMask;
746 info.m_itemId = item;
747
748 if (!GetItem(info))
749 return 0;
750
751 return info.m_state;
752 }
753
754 // Sets the item state
755 bool wxListCtrl::SetItemState(long item, long state, long stateMask)
756 {
757 // NB: don't use SetItem() here as it doesn't work with the virtual list
758 // controls
759 LV_ITEM lvItem;
760 wxZeroMemory(lvItem);
761
762 wxConvertToMSWFlags(state, stateMask, lvItem);
763
764 if ( !::SendMessage(GetHwnd(), LVM_SETITEMSTATE,
765 (WPARAM)item, (LPARAM)&lvItem) )
766 {
767 wxLogLastError(_T("ListView_SetItemState"));
768
769 return FALSE;
770 }
771
772 return TRUE;
773 }
774
775 // Sets the item image
776 bool wxListCtrl::SetItemImage(long item, int image, int WXUNUSED(selImage))
777 {
778 wxListItem info;
779
780 info.m_mask = wxLIST_MASK_IMAGE;
781 info.m_image = image;
782 info.m_itemId = item;
783
784 return SetItem(info);
785 }
786
787 // Gets the item text
788 wxString wxListCtrl::GetItemText(long item) const
789 {
790 wxListItem info;
791
792 info.m_mask = wxLIST_MASK_TEXT;
793 info.m_itemId = item;
794
795 if (!GetItem(info))
796 return wxString("");
797 return info.m_text;
798 }
799
800 // Sets the item text
801 void wxListCtrl::SetItemText(long item, const wxString& str)
802 {
803 wxListItem info;
804
805 info.m_mask = wxLIST_MASK_TEXT;
806 info.m_itemId = item;
807 info.m_text = str;
808
809 SetItem(info);
810 }
811
812 // Gets the item data
813 long wxListCtrl::GetItemData(long item) const
814 {
815 wxListItem info;
816
817 info.m_mask = wxLIST_MASK_DATA;
818 info.m_itemId = item;
819
820 if (!GetItem(info))
821 return 0;
822 return info.m_data;
823 }
824
825 // Sets the item data
826 bool wxListCtrl::SetItemData(long item, long data)
827 {
828 wxListItem info;
829
830 info.m_mask = wxLIST_MASK_DATA;
831 info.m_itemId = item;
832 info.m_data = data;
833
834 return SetItem(info);
835 }
836
837 // Gets the item rectangle
838 bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const
839 {
840 RECT rect2;
841
842 int code2 = LVIR_BOUNDS;
843 if ( code == wxLIST_RECT_BOUNDS )
844 code2 = LVIR_BOUNDS;
845 else if ( code == wxLIST_RECT_ICON )
846 code2 = LVIR_ICON;
847 else if ( code == wxLIST_RECT_LABEL )
848 code2 = LVIR_LABEL;
849
850 #ifdef __WXWINE__
851 bool success = (ListView_GetItemRect(GetHwnd(), (int) item, &rect2 ) != 0);
852 #else
853 bool success = (ListView_GetItemRect(GetHwnd(), (int) item, &rect2, code2) != 0);
854 #endif
855
856 rect.x = rect2.left;
857 rect.y = rect2.top;
858 rect.width = rect2.right - rect2.left;
859 rect.height = rect2.bottom - rect2.top;
860 return success;
861 }
862
863 // Gets the item position
864 bool wxListCtrl::GetItemPosition(long item, wxPoint& pos) const
865 {
866 POINT pt;
867
868 bool success = (ListView_GetItemPosition(GetHwnd(), (int) item, &pt) != 0);
869
870 pos.x = pt.x; pos.y = pt.y;
871 return success;
872 }
873
874 // Sets the item position.
875 bool wxListCtrl::SetItemPosition(long item, const wxPoint& pos)
876 {
877 return (ListView_SetItemPosition(GetHwnd(), (int) item, pos.x, pos.y) != 0);
878 }
879
880 // Gets the number of items in the list control
881 int wxListCtrl::GetItemCount() const
882 {
883 return ListView_GetItemCount(GetHwnd());
884 }
885
886 // Retrieves the spacing between icons in pixels.
887 // If small is TRUE, gets the spacing for the small icon
888 // view, otherwise the large icon view.
889 int wxListCtrl::GetItemSpacing(bool isSmall) const
890 {
891 return ListView_GetItemSpacing(GetHwnd(), (BOOL) isSmall);
892 }
893
894 // Gets the number of selected items in the list control
895 int wxListCtrl::GetSelectedItemCount() const
896 {
897 return ListView_GetSelectedCount(GetHwnd());
898 }
899
900 // Gets the text colour of the listview
901 wxColour wxListCtrl::GetTextColour() const
902 {
903 COLORREF ref = ListView_GetTextColor(GetHwnd());
904 wxColour col(GetRValue(ref), GetGValue(ref), GetBValue(ref));
905 return col;
906 }
907
908 // Sets the text colour of the listview
909 void wxListCtrl::SetTextColour(const wxColour& col)
910 {
911 ListView_SetTextColor(GetHwnd(), PALETTERGB(col.Red(), col.Green(), col.Blue()));
912 }
913
914 // Gets the index of the topmost visible item when in
915 // list or report view
916 long wxListCtrl::GetTopItem() const
917 {
918 return (long) ListView_GetTopIndex(GetHwnd());
919 }
920
921 // Searches for an item, starting from 'item'.
922 // 'geometry' is one of
923 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
924 // 'state' is a state bit flag, one or more of
925 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
926 // item can be -1 to find the first item that matches the
927 // specified flags.
928 // Returns the item or -1 if unsuccessful.
929 long wxListCtrl::GetNextItem(long item, int geom, int state) const
930 {
931 long flags = 0;
932
933 if ( geom == wxLIST_NEXT_ABOVE )
934 flags |= LVNI_ABOVE;
935 if ( geom == wxLIST_NEXT_ALL )
936 flags |= LVNI_ALL;
937 if ( geom == wxLIST_NEXT_BELOW )
938 flags |= LVNI_BELOW;
939 if ( geom == wxLIST_NEXT_LEFT )
940 flags |= LVNI_TOLEFT;
941 if ( geom == wxLIST_NEXT_RIGHT )
942 flags |= LVNI_TORIGHT;
943
944 if ( state & wxLIST_STATE_CUT )
945 flags |= LVNI_CUT;
946 if ( state & wxLIST_STATE_DROPHILITED )
947 flags |= LVNI_DROPHILITED;
948 if ( state & wxLIST_STATE_FOCUSED )
949 flags |= LVNI_FOCUSED;
950 if ( state & wxLIST_STATE_SELECTED )
951 flags |= LVNI_SELECTED;
952
953 return (long) ListView_GetNextItem(GetHwnd(), item, flags);
954 }
955
956
957 wxImageList *wxListCtrl::GetImageList(int which) const
958 {
959 if ( which == wxIMAGE_LIST_NORMAL )
960 {
961 return m_imageListNormal;
962 }
963 else if ( which == wxIMAGE_LIST_SMALL )
964 {
965 return m_imageListSmall;
966 }
967 else if ( which == wxIMAGE_LIST_STATE )
968 {
969 return m_imageListState;
970 }
971 return NULL;
972 }
973
974 void wxListCtrl::SetImageList(wxImageList *imageList, int which)
975 {
976 int flags = 0;
977 if ( which == wxIMAGE_LIST_NORMAL )
978 {
979 flags = LVSIL_NORMAL;
980 if (m_ownsImageListNormal) delete m_imageListNormal;
981 m_imageListNormal = imageList;
982 m_ownsImageListNormal = FALSE;
983 }
984 else if ( which == wxIMAGE_LIST_SMALL )
985 {
986 flags = LVSIL_SMALL;
987 if (m_ownsImageListSmall) delete m_imageListSmall;
988 m_imageListSmall = imageList;
989 m_ownsImageListSmall = FALSE;
990 }
991 else if ( which == wxIMAGE_LIST_STATE )
992 {
993 flags = LVSIL_STATE;
994 if (m_ownsImageListState) delete m_imageListState;
995 m_imageListState = imageList;
996 m_ownsImageListState = FALSE;
997 }
998 ListView_SetImageList(GetHwnd(), (HIMAGELIST) imageList ? imageList->GetHIMAGELIST() : 0, flags);
999 }
1000
1001 void wxListCtrl::AssignImageList(wxImageList *imageList, int which)
1002 {
1003 SetImageList(imageList, which);
1004 if ( which == wxIMAGE_LIST_NORMAL )
1005 m_ownsImageListNormal = TRUE;
1006 else if ( which == wxIMAGE_LIST_SMALL )
1007 m_ownsImageListSmall = TRUE;
1008 else if ( which == wxIMAGE_LIST_STATE )
1009 m_ownsImageListState = TRUE;
1010 }
1011
1012 // ----------------------------------------------------------------------------
1013 // Operations
1014 // ----------------------------------------------------------------------------
1015
1016 // Arranges the items
1017 bool wxListCtrl::Arrange(int flag)
1018 {
1019 UINT code = 0;
1020 if ( flag == wxLIST_ALIGN_LEFT )
1021 code = LVA_ALIGNLEFT;
1022 else if ( flag == wxLIST_ALIGN_TOP )
1023 code = LVA_ALIGNTOP;
1024 else if ( flag == wxLIST_ALIGN_DEFAULT )
1025 code = LVA_DEFAULT;
1026 else if ( flag == wxLIST_ALIGN_SNAP_TO_GRID )
1027 code = LVA_SNAPTOGRID;
1028
1029 return (ListView_Arrange(GetHwnd(), code) != 0);
1030 }
1031
1032 // Deletes an item
1033 bool wxListCtrl::DeleteItem(long item)
1034 {
1035 return (ListView_DeleteItem(GetHwnd(), (int) item) != 0);
1036 }
1037
1038 // Deletes all items
1039 bool wxListCtrl::DeleteAllItems()
1040 {
1041 return (ListView_DeleteAllItems(GetHwnd()) != 0);
1042 }
1043
1044 // Deletes all items
1045 bool wxListCtrl::DeleteAllColumns()
1046 {
1047 while ( m_colCount > 0 )
1048 {
1049 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
1050 {
1051 wxLogLastError(wxT("ListView_DeleteColumn"));
1052
1053 return FALSE;
1054 }
1055
1056 m_colCount--;
1057 }
1058
1059 wxASSERT_MSG( m_colCount == 0, wxT("no columns should be left") );
1060
1061 return TRUE;
1062 }
1063
1064 // Deletes a column
1065 bool wxListCtrl::DeleteColumn(int col)
1066 {
1067 bool success = (ListView_DeleteColumn(GetHwnd(), col) != 0);
1068
1069 if ( success && (m_colCount > 0) )
1070 m_colCount --;
1071 return success;
1072 }
1073
1074 // Clears items, and columns if there are any.
1075 void wxListCtrl::ClearAll()
1076 {
1077 DeleteAllItems();
1078 if ( m_colCount > 0 )
1079 DeleteAllColumns();
1080 }
1081
1082 wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass)
1083 {
1084 wxASSERT( (textControlClass->IsKindOf(CLASSINFO(wxTextCtrl))) );
1085
1086 // VS: ListView_EditLabel requires that the list has focus.
1087 SetFocus();
1088 HWND hWnd = (HWND) ListView_EditLabel(GetHwnd(), item);
1089
1090 if (m_textCtrl)
1091 {
1092 m_textCtrl->SetHWND(0);
1093 m_textCtrl->UnsubclassWin();
1094 delete m_textCtrl;
1095 m_textCtrl = NULL;
1096 }
1097
1098 m_textCtrl = (wxTextCtrl*) textControlClass->CreateObject();
1099 m_textCtrl->SetHWND((WXHWND) hWnd);
1100 m_textCtrl->SubclassWin((WXHWND) hWnd);
1101
1102 return m_textCtrl;
1103 }
1104
1105 // End label editing, optionally cancelling the edit
1106 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel))
1107 {
1108 wxFAIL_MSG( _T("not implemented") );
1109
1110 return FALSE;
1111 }
1112
1113 // Ensures this item is visible
1114 bool wxListCtrl::EnsureVisible(long item)
1115 {
1116 return ListView_EnsureVisible(GetHwnd(), (int) item, FALSE) != 0;
1117 }
1118
1119 // Find an item whose label matches this string, starting from the item after 'start'
1120 // or the beginning if 'start' is -1.
1121 long wxListCtrl::FindItem(long start, const wxString& str, bool partial)
1122 {
1123 LV_FINDINFO findInfo;
1124
1125 findInfo.flags = LVFI_STRING;
1126 if ( partial )
1127 findInfo.flags |= LVFI_PARTIAL;
1128 findInfo.psz = str;
1129
1130 // ListView_FindItem() excludes the first item from search and to look
1131 // through all the items you need to start from -1 which is unnatural and
1132 // inconsistent with the generic version - so we adjust the index
1133 if (start != -1)
1134 start --;
1135 return ListView_FindItem(GetHwnd(), (int) start, &findInfo);
1136 }
1137
1138 // Find an item whose data matches this data, starting from the item after 'start'
1139 // or the beginning if 'start' is -1.
1140 long wxListCtrl::FindItem(long start, long data)
1141 {
1142 LV_FINDINFO findInfo;
1143
1144 findInfo.flags = LVFI_PARAM;
1145 findInfo.lParam = data;
1146
1147 return ListView_FindItem(GetHwnd(), (int) start, & findInfo);
1148 }
1149
1150 // Find an item nearest this position in the specified direction, starting from
1151 // the item after 'start' or the beginning if 'start' is -1.
1152 long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction)
1153 {
1154 LV_FINDINFO findInfo;
1155
1156 findInfo.flags = LVFI_NEARESTXY;
1157 findInfo.pt.x = pt.x;
1158 findInfo.pt.y = pt.y;
1159 findInfo.vkDirection = VK_RIGHT;
1160
1161 if ( direction == wxLIST_FIND_UP )
1162 findInfo.vkDirection = VK_UP;
1163 else if ( direction == wxLIST_FIND_DOWN )
1164 findInfo.vkDirection = VK_DOWN;
1165 else if ( direction == wxLIST_FIND_LEFT )
1166 findInfo.vkDirection = VK_LEFT;
1167 else if ( direction == wxLIST_FIND_RIGHT )
1168 findInfo.vkDirection = VK_RIGHT;
1169
1170 return ListView_FindItem(GetHwnd(), (int) start, & findInfo);
1171 }
1172
1173 // Determines which item (if any) is at the specified point,
1174 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1175 long wxListCtrl::HitTest(const wxPoint& point, int& flags)
1176 {
1177 LV_HITTESTINFO hitTestInfo;
1178 hitTestInfo.pt.x = (int) point.x;
1179 hitTestInfo.pt.y = (int) point.y;
1180
1181 ListView_HitTest(GetHwnd(), & hitTestInfo);
1182
1183 flags = 0;
1184 if ( hitTestInfo.flags & LVHT_ABOVE )
1185 flags |= wxLIST_HITTEST_ABOVE;
1186 if ( hitTestInfo.flags & LVHT_BELOW )
1187 flags |= wxLIST_HITTEST_BELOW;
1188 if ( hitTestInfo.flags & LVHT_NOWHERE )
1189 flags |= wxLIST_HITTEST_NOWHERE;
1190 if ( hitTestInfo.flags & LVHT_ONITEMICON )
1191 flags |= wxLIST_HITTEST_ONITEMICON;
1192 if ( hitTestInfo.flags & LVHT_ONITEMLABEL )
1193 flags |= wxLIST_HITTEST_ONITEMLABEL;
1194 if ( hitTestInfo.flags & LVHT_ONITEMSTATEICON )
1195 flags |= wxLIST_HITTEST_ONITEMSTATEICON;
1196 if ( hitTestInfo.flags & LVHT_TOLEFT )
1197 flags |= wxLIST_HITTEST_TOLEFT;
1198 if ( hitTestInfo.flags & LVHT_TORIGHT )
1199 flags |= wxLIST_HITTEST_TORIGHT;
1200
1201 return (long) hitTestInfo.iItem;
1202 }
1203
1204 // Inserts an item, returning the index of the new item if successful,
1205 // -1 otherwise.
1206 long wxListCtrl::InsertItem(wxListItem& info)
1207 {
1208 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1209
1210 LV_ITEM item;
1211 wxConvertToMSWListItem(this, info, item);
1212
1213 // check whether it has any custom attributes
1214 if ( info.HasAttributes() )
1215 {
1216
1217 wxListItemAttr *attr;
1218 attr = (wxListItemAttr*) m_attrs.Get(item.iItem);
1219
1220 if (attr == NULL)
1221
1222 m_attrs.Put(item.iItem, (wxObject *)new wxListItemAttr(*info.GetAttributes()));
1223
1224 else *attr = *info.GetAttributes();
1225
1226 m_hasAnyAttr = TRUE;
1227 }
1228
1229 return (long) ListView_InsertItem(GetHwnd(), & item);
1230 }
1231
1232 long wxListCtrl::InsertItem(long index, const wxString& label)
1233 {
1234 wxListItem info;
1235 info.m_text = label;
1236 info.m_mask = wxLIST_MASK_TEXT;
1237 info.m_itemId = index;
1238 return InsertItem(info);
1239 }
1240
1241 // Inserts an image item
1242 long wxListCtrl::InsertItem(long index, int imageIndex)
1243 {
1244 wxListItem info;
1245 info.m_image = imageIndex;
1246 info.m_mask = wxLIST_MASK_IMAGE;
1247 info.m_itemId = index;
1248 return InsertItem(info);
1249 }
1250
1251 // Inserts an image/string item
1252 long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex)
1253 {
1254 wxListItem info;
1255 info.m_image = imageIndex;
1256 info.m_text = label;
1257 info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT;
1258 info.m_itemId = index;
1259 return InsertItem(info);
1260 }
1261
1262 // For list view mode (only), inserts a column.
1263 long wxListCtrl::InsertColumn(long col, wxListItem& item)
1264 {
1265 LV_COLUMN lvCol;
1266 lvCol.mask = 0;
1267 lvCol.fmt = 0;
1268 lvCol.pszText = NULL;
1269
1270 if ( item.m_mask & wxLIST_MASK_TEXT )
1271 {
1272 lvCol.mask |= LVCF_TEXT;
1273 lvCol.pszText = WXSTRINGCAST item.m_text;
1274 lvCol.cchTextMax = 0; // Ignored
1275 }
1276 if ( item.m_mask & wxLIST_MASK_FORMAT )
1277 {
1278 lvCol.mask |= LVCF_FMT;
1279
1280 if ( item.m_format == wxLIST_FORMAT_LEFT )
1281 lvCol.fmt = LVCFMT_LEFT;
1282 if ( item.m_format == wxLIST_FORMAT_RIGHT )
1283 lvCol.fmt = LVCFMT_RIGHT;
1284 if ( item.m_format == wxLIST_FORMAT_CENTRE )
1285 lvCol.fmt = LVCFMT_CENTER;
1286 }
1287
1288 lvCol.mask |= LVCF_WIDTH;
1289 if ( item.m_mask & wxLIST_MASK_WIDTH )
1290 {
1291 if ( item.m_width == wxLIST_AUTOSIZE)
1292 lvCol.cx = LVSCW_AUTOSIZE;
1293 else if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER)
1294 lvCol.cx = LVSCW_AUTOSIZE_USEHEADER;
1295 else
1296 lvCol.cx = item.m_width;
1297 }
1298 else
1299 {
1300 // always give some width to the new column: this one is compatible
1301 // with wxGTK
1302 lvCol.cx = 80;
1303 }
1304
1305 lvCol.mask |= LVCF_SUBITEM;
1306 lvCol.iSubItem = col;
1307
1308 bool success = ListView_InsertColumn(GetHwnd(), col, & lvCol) != -1;
1309 if ( success )
1310 {
1311 m_colCount++;
1312 }
1313 else
1314 {
1315 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1316 lvCol.pszText);
1317 }
1318
1319 return success;
1320 }
1321
1322 long wxListCtrl::InsertColumn(long col,
1323 const wxString& heading,
1324 int format,
1325 int width)
1326 {
1327 wxListItem item;
1328 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
1329 item.m_text = heading;
1330 if ( width > -1 )
1331 {
1332 item.m_mask |= wxLIST_MASK_WIDTH;
1333 item.m_width = width;
1334 }
1335 item.m_format = format;
1336
1337 return InsertColumn(col, item);
1338 }
1339
1340 // Scrolls the list control. If in icon, small icon or report view mode,
1341 // x specifies the number of pixels to scroll. If in list view mode, x
1342 // specifies the number of columns to scroll.
1343 // If in icon, small icon or list view mode, y specifies the number of pixels
1344 // to scroll. If in report view mode, y specifies the number of lines to scroll.
1345 bool wxListCtrl::ScrollList(int dx, int dy)
1346 {
1347 return (ListView_Scroll(GetHwnd(), dx, dy) != 0);
1348 }
1349
1350 // Sort items.
1351
1352 // fn is a function which takes 3 long arguments: item1, item2, data.
1353 // item1 is the long data associated with a first item (NOT the index).
1354 // item2 is the long data associated with a second item (NOT the index).
1355 // data is the same value as passed to SortItems.
1356 // The return value is a negative number if the first item should precede the second
1357 // item, a positive number of the second item should precede the first,
1358 // or zero if the two items are equivalent.
1359
1360 // data is arbitrary data to be passed to the sort function.
1361 bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data)
1362 {
1363 return (ListView_SortItems(GetHwnd(), (PFNLVCOMPARE) fn, data) != 0);
1364 }
1365
1366 // ----------------------------------------------------------------------------
1367 // message processing
1368 // ----------------------------------------------------------------------------
1369
1370 bool wxListCtrl::MSWCommand(WXUINT cmd, WXWORD id)
1371 {
1372 if (cmd == EN_UPDATE)
1373 {
1374 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, id);
1375 event.SetEventObject( this );
1376 ProcessCommand(event);
1377 return TRUE;
1378 }
1379 else if (cmd == EN_KILLFOCUS)
1380 {
1381 wxCommandEvent event(wxEVT_KILL_FOCUS, id);
1382 event.SetEventObject( this );
1383 ProcessCommand(event);
1384 return TRUE;
1385 }
1386 else
1387 return FALSE;
1388 }
1389
1390 bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
1391 {
1392 // prepare the event
1393 // -----------------
1394
1395 wxListEvent event(wxEVT_NULL, m_windowId);
1396 wxEventType eventType = wxEVT_NULL;
1397
1398 NMHDR *nmhdr = (NMHDR *)lParam;
1399
1400 // almost all messages use NM_LISTVIEW
1401 NM_LISTVIEW *nmLV = (NM_LISTVIEW *)nmhdr;
1402
1403 // this is true for almost all events
1404 event.m_item.m_data = nmLV->lParam;
1405
1406 switch ( nmhdr->code )
1407 {
1408 case LVN_BEGINRDRAG:
1409 eventType = wxEVT_COMMAND_LIST_BEGIN_RDRAG;
1410 // fall through
1411
1412 case LVN_BEGINDRAG:
1413 if ( eventType == wxEVT_NULL )
1414 {
1415 eventType = wxEVT_COMMAND_LIST_BEGIN_DRAG;
1416 }
1417
1418 event.m_itemIndex = nmLV->iItem;
1419 event.m_pointDrag.x = nmLV->ptAction.x;
1420 event.m_pointDrag.y = nmLV->ptAction.y;
1421 break;
1422
1423 case LVN_BEGINLABELEDIT:
1424 {
1425 eventType = wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT;
1426 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1427 wxConvertFromMSWListItem(GetHwnd(), event.m_item, info->item);
1428 event.m_itemIndex = event.m_item.m_itemId;
1429 }
1430 break;
1431
1432 case LVN_COLUMNCLICK:
1433 eventType = wxEVT_COMMAND_LIST_COL_CLICK;
1434 event.m_itemIndex = -1;
1435 event.m_col = nmLV->iSubItem;
1436 break;
1437
1438 case LVN_DELETEALLITEMS:
1439 eventType = wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS;
1440 event.m_itemIndex = -1;
1441
1442 FreeAllAttrs();
1443
1444 break;
1445
1446 case LVN_DELETEITEM:
1447 eventType = wxEVT_COMMAND_LIST_DELETE_ITEM;
1448 event.m_itemIndex = nmLV->iItem;
1449
1450 if ( m_hasAnyAttr )
1451 {
1452 delete (wxListItemAttr *)m_attrs.Delete(nmLV->iItem);
1453 }
1454 break;
1455
1456 case LVN_ENDLABELEDIT:
1457 {
1458 eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT;
1459 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1460 wxConvertFromMSWListItem(GetHwnd(), event.m_item, info->item);
1461 if ( info->item.pszText == NULL || info->item.iItem == -1 )
1462 return FALSE;
1463
1464 event.m_itemIndex = event.m_item.m_itemId;
1465 }
1466 break;
1467
1468 case LVN_SETDISPINFO:
1469 {
1470 eventType = wxEVT_COMMAND_LIST_SET_INFO;
1471 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1472 wxConvertFromMSWListItem(GetHwnd(), event.m_item, info->item);
1473 }
1474 break;
1475
1476 case LVN_INSERTITEM:
1477 eventType = wxEVT_COMMAND_LIST_INSERT_ITEM;
1478 event.m_itemIndex = nmLV->iItem;
1479 break;
1480
1481 case LVN_ITEMCHANGED:
1482 // This needs to be sent to wxListCtrl as a rather more concrete
1483 // event. For now, just detect a selection or deselection.
1484 if ( (nmLV->uNewState & LVIS_SELECTED) && !(nmLV->uOldState & LVIS_SELECTED) )
1485 {
1486 eventType = wxEVT_COMMAND_LIST_ITEM_SELECTED;
1487 event.m_itemIndex = nmLV->iItem;
1488 }
1489 else if ( !(nmLV->uNewState & LVIS_SELECTED) && (nmLV->uOldState & LVIS_SELECTED) )
1490 {
1491 eventType = wxEVT_COMMAND_LIST_ITEM_DESELECTED;
1492 event.m_itemIndex = nmLV->iItem;
1493 }
1494 else
1495 {
1496 return FALSE;
1497 }
1498 break;
1499
1500 case LVN_KEYDOWN:
1501 {
1502 LV_KEYDOWN *info = (LV_KEYDOWN *)lParam;
1503 WORD wVKey = info->wVKey;
1504
1505 // get the current selection
1506 long lItem = GetNextItem(-1,
1507 wxLIST_NEXT_ALL,
1508 wxLIST_STATE_SELECTED);
1509
1510 // <Enter> or <Space> activate the selected item if any (but
1511 // not with Shift and/or Ctrl as then they have a predefined
1512 // meaning for the list view)
1513 if ( lItem != -1 &&
1514 (wVKey == VK_RETURN || wVKey == VK_SPACE) &&
1515 !(wxIsShiftDown() || wxIsCtrlDown()) )
1516 {
1517 eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
1518 }
1519 else
1520 {
1521 eventType = wxEVT_COMMAND_LIST_KEY_DOWN;
1522 event.m_code = wxCharCodeMSWToWX(wVKey);
1523 }
1524
1525 event.m_itemIndex =
1526 event.m_item.m_itemId = lItem;
1527
1528 if ( lItem != -1 )
1529 {
1530 // fill the other fields too
1531 event.m_item.m_text = GetItemText(lItem);
1532 event.m_item.m_data = GetItemData(lItem);
1533 }
1534 }
1535 break;
1536
1537 case NM_DBLCLK:
1538 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1539 // anything else
1540 if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
1541 {
1542 return TRUE;
1543 }
1544
1545 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
1546 // if it happened on an item (and not on empty place)
1547 if ( nmLV->iItem == -1 )
1548 {
1549 // not on item
1550 return FALSE;
1551 }
1552
1553 eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
1554 event.m_itemIndex = nmLV->iItem;
1555 event.m_item.m_text = GetItemText(nmLV->iItem);
1556 event.m_item.m_data = GetItemData(nmLV->iItem);
1557 break;
1558
1559 case NM_RCLICK:
1560 /* TECH NOTE: NM_RCLICK isn't really good enough here. We want to
1561 subclass and check for the actual WM_RBUTTONDOWN message,
1562 because NM_RCLICK waits for the WM_RBUTTONUP message as well
1563 before firing off. We want to have notify events for both down
1564 -and- up. */
1565 {
1566 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
1567 // don't do anything else
1568 if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
1569 {
1570 return TRUE;
1571 }
1572
1573 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1574 LV_HITTESTINFO lvhti;
1575 wxZeroMemory(lvhti);
1576
1577 ::GetCursorPos(&(lvhti.pt));
1578 ::ScreenToClient(GetHwnd(),&(lvhti.pt));
1579 if ( ListView_HitTest(GetHwnd(),&lvhti) != -1 )
1580 {
1581 if ( lvhti.flags & LVHT_ONITEM )
1582 {
1583 eventType = wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK;
1584 event.m_itemIndex = lvhti.iItem;
1585 event.m_pointDrag.x = lvhti.pt.x;
1586 event.m_pointDrag.y = lvhti.pt.y;
1587 }
1588 }
1589 }
1590 break;
1591
1592 #if 0
1593 case NM_MCLICK: // ***** THERE IS NO NM_MCLICK. Subclass anyone? ******
1594 {
1595 // if the user processes it in wxEVT_COMMAND_MIDDLE_CLICK(), don't do
1596 // anything else
1597 if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
1598 {
1599 return TRUE;
1600 }
1601
1602 // else translate it into wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK event
1603 eventType = wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK;
1604 NMITEMACTIVATE* hdr = (NMITEMACTIVATE*)lParam;
1605 event.m_itemIndex = hdr->iItem;
1606 }
1607 break;
1608 #endif // 0
1609
1610 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300
1611 case NM_CUSTOMDRAW:
1612 *result = OnCustomDraw(lParam);
1613
1614 return TRUE;
1615 #endif // _WIN32_IE >= 0x300
1616
1617 case LVN_GETDISPINFO:
1618 if ( IsVirtual() )
1619 {
1620 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1621
1622 LV_ITEM& lvi = info->item;
1623 long item = lvi.iItem;
1624
1625 if ( lvi.mask & LVIF_TEXT )
1626 {
1627 wxString text = OnGetItemText(item, lvi.iSubItem);
1628 wxStrncpy(lvi.pszText, text, lvi.cchTextMax);
1629 }
1630
1631 if ( lvi.mask & LVIF_IMAGE )
1632 {
1633 lvi.iImage = OnGetItemImage(item);
1634 }
1635
1636 // a little dose of healthy paranoia: as we never use
1637 // LVM_SETCALLBACKMASK we're not supposed to get these ones
1638 wxASSERT_MSG( !(lvi.mask & LVIF_STATE),
1639 _T("we don't support state callbacks yet!") );
1640
1641 return TRUE;
1642 }
1643 // fall through
1644
1645 default:
1646 return wxControl::MSWOnNotify(idCtrl, lParam, result);
1647 }
1648
1649 // process the event
1650 // -----------------
1651
1652 event.SetEventObject( this );
1653 event.SetEventType(eventType);
1654
1655 if ( !GetEventHandler()->ProcessEvent(event) )
1656 return FALSE;
1657
1658 // post processing
1659 // ---------------
1660
1661 switch ( nmhdr->code )
1662 {
1663 case LVN_DELETEALLITEMS:
1664 // always return TRUE to suppress all additional LVN_DELETEITEM
1665 // notifications - this makes deleting all items from a list ctrl
1666 // much faster
1667 *result = TRUE;
1668
1669 return TRUE;
1670
1671 case LVN_ENDLABELEDIT:
1672 {
1673 *result = event.IsAllowed();
1674 return TRUE;
1675 }
1676 }
1677
1678 *result = !event.IsAllowed();
1679
1680 return TRUE;
1681 }
1682
1683 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300
1684
1685 WXLPARAM wxListCtrl::OnCustomDraw(WXLPARAM lParam)
1686 {
1687 LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
1688 NMCUSTOMDRAW& nmcd = lplvcd->nmcd;
1689 switch ( nmcd.dwDrawStage )
1690 {
1691 case CDDS_PREPAINT:
1692 // if we've got any items with non standard attributes,
1693 // notify us before painting each item
1694 //
1695 // for virtual controls, always suppose that we have attributes as
1696 // there is no way to check for this
1697 return IsVirtual() || m_hasAnyAttr ? CDRF_NOTIFYITEMDRAW
1698 : CDRF_DODEFAULT;
1699
1700 case CDDS_ITEMPREPAINT:
1701 {
1702 size_t item = (size_t)nmcd.dwItemSpec;
1703 if ( item >= (size_t)GetItemCount() )
1704 {
1705 // we get this message with item == 0 for an empty control,
1706 // we must ignore it as calling OnGetItemAttr() would be
1707 // wrong
1708 return CDRF_DODEFAULT;
1709 }
1710
1711 wxListItemAttr *attr =
1712 IsVirtual() ? OnGetItemAttr(item)
1713 : (wxListItemAttr *)m_attrs.Get(item);
1714
1715 if ( !attr )
1716 {
1717 // nothing to do for this item
1718 return CDRF_DODEFAULT;
1719 }
1720
1721 HFONT hFont;
1722 wxColour colText, colBack;
1723 if ( attr->HasFont() )
1724 {
1725 wxFont font = attr->GetFont();
1726 hFont = (HFONT)font.GetResourceHandle();
1727 }
1728 else
1729 {
1730 hFont = 0;
1731 }
1732
1733 if ( attr->HasTextColour() )
1734 {
1735 colText = attr->GetTextColour();
1736 }
1737 else
1738 {
1739 colText = GetTextColour();
1740 }
1741
1742 if ( attr->HasBackgroundColour() )
1743 {
1744 colBack = attr->GetBackgroundColour();
1745 }
1746 else
1747 {
1748 colBack = GetBackgroundColour();
1749 }
1750
1751 lplvcd->clrText = wxColourToRGB(colText);
1752 lplvcd->clrTextBk = wxColourToRGB(colBack);
1753
1754 // note that if we wanted to set colours for
1755 // individual columns (subitems), we would have
1756 // returned CDRF_NOTIFYSUBITEMREDRAW from here
1757 if ( hFont )
1758 {
1759 ::SelectObject(nmcd.hdc, hFont);
1760
1761 return CDRF_NEWFONT;
1762 }
1763 }
1764 // fall through to return CDRF_DODEFAULT
1765
1766 default:
1767 return CDRF_DODEFAULT;
1768 }
1769 }
1770
1771 #endif // NM_CUSTOMDRAW supported
1772
1773 // Necessary for drawing hrules and vrules, if specified
1774 void wxListCtrl::OnPaint(wxPaintEvent& event)
1775 {
1776 wxPaintDC dc(this);
1777
1778 wxControl::OnPaint(event);
1779
1780 // Reset the device origin since it may have been set
1781 dc.SetDeviceOrigin(0, 0);
1782
1783 bool drawHRules = ((GetWindowStyle() & wxLC_HRULES) != 0);
1784 bool drawVRules = ((GetWindowStyle() & wxLC_VRULES) != 0);
1785
1786 if (!drawHRules && !drawVRules)
1787 return;
1788 if ((GetWindowStyle() & wxLC_REPORT) == 0)
1789 return;
1790
1791 wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
1792 dc.SetPen(pen);
1793 dc.SetBrush(* wxTRANSPARENT_BRUSH);
1794
1795 wxSize clientSize = GetClientSize();
1796 wxRect itemRect;
1797 int cy=0;
1798
1799 int itemCount = GetItemCount();
1800 int i;
1801 for (i = 0; i < itemCount; i++)
1802 {
1803 if (GetItemRect(i, itemRect))
1804 {
1805 cy = itemRect.GetTop();
1806 if (i != 0) // Don't draw the first one
1807 {
1808 dc.DrawLine(0, cy, clientSize.x, cy);
1809 }
1810 // Draw last line
1811 if (i == (GetItemCount() - 1))
1812 {
1813 cy = itemRect.GetBottom();
1814 dc.DrawLine(0, cy, clientSize.x, cy);
1815 }
1816 }
1817 }
1818 i = (GetItemCount() - 1);
1819 if (drawVRules && (i > -1))
1820 {
1821 wxRect firstItemRect;
1822 GetItemRect(0, firstItemRect);
1823
1824 if (GetItemRect(i, itemRect))
1825 {
1826 int col;
1827 int x = itemRect.GetX();
1828 for (col = 0; col < GetColumnCount(); col++)
1829 {
1830 int colWidth = GetColumnWidth(col);
1831 x += colWidth ;
1832 dc.DrawLine(x, firstItemRect.GetY() - 2, x, itemRect.GetBottom());
1833 }
1834 }
1835 }
1836 }
1837
1838 // ----------------------------------------------------------------------------
1839 // virtual list controls
1840 // ----------------------------------------------------------------------------
1841
1842 wxString wxListCtrl::OnGetItemText(long item, long col) const
1843 {
1844 // this is a pure virtual function, in fact - which is not really pure
1845 // because the controls which are not virtual don't need to implement it
1846 wxFAIL_MSG( _T("not supposed to be called") );
1847
1848 return wxEmptyString;
1849 }
1850
1851 int wxListCtrl::OnGetItemImage(long item) const
1852 {
1853 // same as above
1854 wxFAIL_MSG( _T("not supposed to be called") );
1855
1856 return -1;
1857 }
1858
1859 wxListItemAttr *wxListCtrl::OnGetItemAttr(long item) const
1860 {
1861 wxASSERT_MSG( item >= 0 && item < GetItemCount(),
1862 _T("invalid item index in OnGetItemAttr()") );
1863
1864 // no attributes by default
1865 return NULL;
1866 }
1867
1868 void wxListCtrl::SetItemCount(long count)
1869 {
1870 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
1871
1872 if ( !::SendMessage(GetHwnd(), LVM_SETITEMCOUNT, (WPARAM)count, 0) )
1873 {
1874 wxLogLastError(_T("ListView_SetItemCount"));
1875 }
1876 }
1877
1878 void wxListCtrl::RefreshItem(long item)
1879 {
1880 if ( !ListView_Update(GetHwnd(), item) )
1881 {
1882 wxLogLastError(_T("ListView_Update"));
1883 }
1884 }
1885
1886 void wxListCtrl::RefreshItems(long itemFrom, long itemTo)
1887 {
1888 for ( long item = itemFrom; item <= itemTo; item++ )
1889 {
1890 RefreshItem(item);
1891 }
1892 }
1893
1894 // ----------------------------------------------------------------------------
1895 // wxListItem
1896 // ----------------------------------------------------------------------------
1897
1898 // List item structure
1899 wxListItem::wxListItem()
1900 {
1901 m_mask = 0;
1902 m_itemId = 0;
1903 m_col = 0;
1904 m_state = 0;
1905 m_stateMask = 0;
1906 m_image = 0;
1907 m_data = 0;
1908
1909 m_format = wxLIST_FORMAT_CENTRE;
1910 m_width = 0;
1911
1912 m_attr = NULL;
1913 }
1914
1915 void wxListItem::Clear()
1916 {
1917 m_mask = 0;
1918 m_itemId = 0;
1919 m_col = 0;
1920 m_state = 0;
1921 m_stateMask = 0;
1922 m_image = 0;
1923 m_data = 0;
1924 m_format = wxLIST_FORMAT_CENTRE;
1925 m_width = 0;
1926 m_text = wxEmptyString;
1927
1928 if (m_attr) delete m_attr;
1929 m_attr = NULL;
1930 }
1931
1932 void wxListItem::ClearAttributes()
1933 {
1934 if (m_attr) delete m_attr;
1935 m_attr = NULL;
1936 }
1937
1938 static void wxConvertFromMSWListItem(HWND hwndListCtrl,
1939 wxListItem& info,
1940 LV_ITEM& lvItem)
1941 {
1942 info.m_data = lvItem.lParam;
1943 info.m_mask = 0;
1944 info.m_state = 0;
1945 info.m_stateMask = 0;
1946 info.m_itemId = lvItem.iItem;
1947
1948 long oldMask = lvItem.mask;
1949
1950 bool needText = FALSE;
1951 if (hwndListCtrl != 0)
1952 {
1953 if ( lvItem.mask & LVIF_TEXT )
1954 needText = FALSE;
1955 else
1956 needText = TRUE;
1957
1958 if ( needText )
1959 {
1960 lvItem.pszText = new wxChar[513];
1961 lvItem.cchTextMax = 512;
1962 }
1963 lvItem.mask |= LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
1964 ::SendMessage(hwndListCtrl, LVM_GETITEM, 0, (LPARAM)& lvItem);
1965 }
1966
1967 if ( lvItem.mask & LVIF_STATE )
1968 {
1969 info.m_mask |= wxLIST_MASK_STATE;
1970
1971 if ( lvItem.stateMask & LVIS_CUT)
1972 {
1973 info.m_stateMask |= wxLIST_STATE_CUT;
1974 if ( lvItem.state & LVIS_CUT )
1975 info.m_state |= wxLIST_STATE_CUT;
1976 }
1977 if ( lvItem.stateMask & LVIS_DROPHILITED)
1978 {
1979 info.m_stateMask |= wxLIST_STATE_DROPHILITED;
1980 if ( lvItem.state & LVIS_DROPHILITED )
1981 info.m_state |= wxLIST_STATE_DROPHILITED;
1982 }
1983 if ( lvItem.stateMask & LVIS_FOCUSED)
1984 {
1985 info.m_stateMask |= wxLIST_STATE_FOCUSED;
1986 if ( lvItem.state & LVIS_FOCUSED )
1987 info.m_state |= wxLIST_STATE_FOCUSED;
1988 }
1989 if ( lvItem.stateMask & LVIS_SELECTED)
1990 {
1991 info.m_stateMask |= wxLIST_STATE_SELECTED;
1992 if ( lvItem.state & LVIS_SELECTED )
1993 info.m_state |= wxLIST_STATE_SELECTED;
1994 }
1995 }
1996
1997 if ( lvItem.mask & LVIF_TEXT )
1998 {
1999 info.m_mask |= wxLIST_MASK_TEXT;
2000 info.m_text = lvItem.pszText;
2001 }
2002 if ( lvItem.mask & LVIF_IMAGE )
2003 {
2004 info.m_mask |= wxLIST_MASK_IMAGE;
2005 info.m_image = lvItem.iImage;
2006 }
2007 if ( lvItem.mask & LVIF_PARAM )
2008 info.m_mask |= wxLIST_MASK_DATA;
2009 if ( lvItem.mask & LVIF_DI_SETITEM )
2010 info.m_mask |= wxLIST_SET_ITEM;
2011 info.m_col = lvItem.iSubItem;
2012
2013 if (needText)
2014 {
2015 if (lvItem.pszText)
2016 delete[] lvItem.pszText;
2017 }
2018 lvItem.mask = oldMask;
2019 }
2020
2021 static void wxConvertToMSWFlags(long state, long stateMask, LV_ITEM& lvItem)
2022 {
2023 if (stateMask & wxLIST_STATE_CUT)
2024 {
2025 lvItem.stateMask |= LVIS_CUT;
2026 if (state & wxLIST_STATE_CUT)
2027 lvItem.state |= LVIS_CUT;
2028 }
2029 if (stateMask & wxLIST_STATE_DROPHILITED)
2030 {
2031 lvItem.stateMask |= LVIS_DROPHILITED;
2032 if (state & wxLIST_STATE_DROPHILITED)
2033 lvItem.state |= LVIS_DROPHILITED;
2034 }
2035 if (stateMask & wxLIST_STATE_FOCUSED)
2036 {
2037 lvItem.stateMask |= LVIS_FOCUSED;
2038 if (state & wxLIST_STATE_FOCUSED)
2039 lvItem.state |= LVIS_FOCUSED;
2040 }
2041 if (stateMask & wxLIST_STATE_SELECTED)
2042 {
2043 lvItem.stateMask |= LVIS_SELECTED;
2044 if (state & wxLIST_STATE_SELECTED)
2045 lvItem.state |= LVIS_SELECTED;
2046 }
2047 }
2048
2049 static void wxConvertToMSWListItem(const wxListCtrl *ctrl,
2050 const wxListItem& info,
2051 LV_ITEM& lvItem)
2052 {
2053 lvItem.iItem = (int) info.m_itemId;
2054
2055 lvItem.iImage = info.m_image;
2056 lvItem.lParam = info.m_data;
2057 lvItem.stateMask = 0;
2058 lvItem.state = 0;
2059 lvItem.mask = 0;
2060 lvItem.iSubItem = info.m_col;
2061
2062 if (info.m_mask & wxLIST_MASK_STATE)
2063 {
2064 lvItem.mask |= LVIF_STATE;
2065
2066 wxConvertToMSWFlags(info.m_state, info.m_stateMask, lvItem);
2067 }
2068
2069 if (info.m_mask & wxLIST_MASK_TEXT)
2070 {
2071 lvItem.mask |= LVIF_TEXT;
2072 if ( ctrl->GetWindowStyleFlag() & wxLC_USER_TEXT )
2073 {
2074 lvItem.pszText = LPSTR_TEXTCALLBACK;
2075 }
2076 else
2077 {
2078 // pszText is not const, hence the cast
2079 lvItem.pszText = (wxChar *)info.m_text.c_str();
2080 if ( lvItem.pszText )
2081 lvItem.cchTextMax = info.m_text.Length();
2082 else
2083 lvItem.cchTextMax = 0;
2084 }
2085 }
2086 if (info.m_mask & wxLIST_MASK_IMAGE)
2087 lvItem.mask |= LVIF_IMAGE;
2088 if (info.m_mask & wxLIST_MASK_DATA)
2089 lvItem.mask |= LVIF_PARAM;
2090 }
2091
2092 // ----------------------------------------------------------------------------
2093 // List event
2094 // ----------------------------------------------------------------------------
2095
2096 IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
2097
2098 wxListEvent::wxListEvent(wxEventType commandType, int id)
2099 : wxNotifyEvent(commandType, id)
2100 {
2101 m_code = 0;
2102 m_itemIndex = 0;
2103 m_oldItemIndex = 0;
2104 m_col = 0;
2105 m_cancelled = FALSE;
2106 }
2107
2108 #endif // wxUSE_LISTCTRL