]> git.saurik.com Git - wxWidgets.git/blob - src/msw/listctrl.cpp
fix for custom bitmap setting for the first page
[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 // give NULL as hwnd as we already have everything we need
673 wxConvertFromMSWListItem(NULL, info, lvItem);
674 }
675
676 if (lvItem.pszText)
677 delete[] lvItem.pszText;
678
679 return success;
680 }
681
682 // Sets information about the item
683 bool wxListCtrl::SetItem(wxListItem& info)
684 {
685 LV_ITEM item;
686 wxConvertToMSWListItem(this, info, item);
687
688 item.cchTextMax = 0;
689 if ( !ListView_SetItem(GetHwnd(), &item) )
690 {
691 wxLogDebug(_T("ListView_SetItem() failed"));
692
693 return FALSE;
694 }
695
696 // we need to update the item immediately to show the new image
697 bool updateNow = (info.m_mask & wxLIST_MASK_IMAGE) != 0;
698
699 // check whether it has any custom attributes
700 if ( info.HasAttributes() )
701 {
702 wxListItemAttr *attr = (wxListItemAttr *)m_attrs.Get(item.iItem);
703
704 if ( attr == NULL )
705 m_attrs.Put(item.iItem, (wxObject *)new wxListItemAttr(*info.GetAttributes()));
706 else
707 *attr = *info.GetAttributes();
708
709 m_hasAnyAttr = TRUE;
710
711 // if the colour has changed, we must redraw the item
712 updateNow = TRUE;
713 }
714
715 if ( updateNow )
716 {
717 // we need this to make the change visible right now
718 ListView_Update(GetHwnd(), item.iItem);
719 }
720
721 return TRUE;
722 }
723
724 long wxListCtrl::SetItem(long index, int col, const wxString& label, int imageId)
725 {
726 wxListItem info;
727 info.m_text = label;
728 info.m_mask = wxLIST_MASK_TEXT;
729 info.m_itemId = index;
730 info.m_col = col;
731 if ( imageId > -1 )
732 {
733 info.m_image = imageId;
734 info.m_mask |= wxLIST_MASK_IMAGE;
735 }
736 return SetItem(info);
737 }
738
739
740 // Gets the item state
741 int wxListCtrl::GetItemState(long item, long stateMask) const
742 {
743 wxListItem info;
744
745 info.m_mask = wxLIST_MASK_STATE;
746 info.m_stateMask = stateMask;
747 info.m_itemId = item;
748
749 if (!GetItem(info))
750 return 0;
751
752 return info.m_state;
753 }
754
755 // Sets the item state
756 bool wxListCtrl::SetItemState(long item, long state, long stateMask)
757 {
758 // NB: don't use SetItem() here as it doesn't work with the virtual list
759 // controls
760 LV_ITEM lvItem;
761 wxZeroMemory(lvItem);
762
763 wxConvertToMSWFlags(state, stateMask, lvItem);
764
765 if ( !::SendMessage(GetHwnd(), LVM_SETITEMSTATE,
766 (WPARAM)item, (LPARAM)&lvItem) )
767 {
768 wxLogLastError(_T("ListView_SetItemState"));
769
770 return FALSE;
771 }
772
773 return TRUE;
774 }
775
776 // Sets the item image
777 bool wxListCtrl::SetItemImage(long item, int image, int WXUNUSED(selImage))
778 {
779 wxListItem info;
780
781 info.m_mask = wxLIST_MASK_IMAGE;
782 info.m_image = image;
783 info.m_itemId = item;
784
785 return SetItem(info);
786 }
787
788 // Gets the item text
789 wxString wxListCtrl::GetItemText(long item) const
790 {
791 wxListItem info;
792
793 info.m_mask = wxLIST_MASK_TEXT;
794 info.m_itemId = item;
795
796 if (!GetItem(info))
797 return wxString("");
798 return info.m_text;
799 }
800
801 // Sets the item text
802 void wxListCtrl::SetItemText(long item, const wxString& str)
803 {
804 wxListItem info;
805
806 info.m_mask = wxLIST_MASK_TEXT;
807 info.m_itemId = item;
808 info.m_text = str;
809
810 SetItem(info);
811 }
812
813 // Gets the item data
814 long wxListCtrl::GetItemData(long item) const
815 {
816 wxListItem info;
817
818 info.m_mask = wxLIST_MASK_DATA;
819 info.m_itemId = item;
820
821 if (!GetItem(info))
822 return 0;
823 return info.m_data;
824 }
825
826 // Sets the item data
827 bool wxListCtrl::SetItemData(long item, long data)
828 {
829 wxListItem info;
830
831 info.m_mask = wxLIST_MASK_DATA;
832 info.m_itemId = item;
833 info.m_data = data;
834
835 return SetItem(info);
836 }
837
838 // Gets the item rectangle
839 bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const
840 {
841 RECT rect2;
842
843 int code2 = LVIR_BOUNDS;
844 if ( code == wxLIST_RECT_BOUNDS )
845 code2 = LVIR_BOUNDS;
846 else if ( code == wxLIST_RECT_ICON )
847 code2 = LVIR_ICON;
848 else if ( code == wxLIST_RECT_LABEL )
849 code2 = LVIR_LABEL;
850
851 #ifdef __WXWINE__
852 bool success = (ListView_GetItemRect(GetHwnd(), (int) item, &rect2 ) != 0);
853 #else
854 bool success = (ListView_GetItemRect(GetHwnd(), (int) item, &rect2, code2) != 0);
855 #endif
856
857 rect.x = rect2.left;
858 rect.y = rect2.top;
859 rect.width = rect2.right - rect2.left;
860 rect.height = rect2.bottom - rect2.top;
861 return success;
862 }
863
864 // Gets the item position
865 bool wxListCtrl::GetItemPosition(long item, wxPoint& pos) const
866 {
867 POINT pt;
868
869 bool success = (ListView_GetItemPosition(GetHwnd(), (int) item, &pt) != 0);
870
871 pos.x = pt.x; pos.y = pt.y;
872 return success;
873 }
874
875 // Sets the item position.
876 bool wxListCtrl::SetItemPosition(long item, const wxPoint& pos)
877 {
878 return (ListView_SetItemPosition(GetHwnd(), (int) item, pos.x, pos.y) != 0);
879 }
880
881 // Gets the number of items in the list control
882 int wxListCtrl::GetItemCount() const
883 {
884 return ListView_GetItemCount(GetHwnd());
885 }
886
887 // Retrieves the spacing between icons in pixels.
888 // If small is TRUE, gets the spacing for the small icon
889 // view, otherwise the large icon view.
890 int wxListCtrl::GetItemSpacing(bool isSmall) const
891 {
892 return ListView_GetItemSpacing(GetHwnd(), (BOOL) isSmall);
893 }
894
895 // Gets the number of selected items in the list control
896 int wxListCtrl::GetSelectedItemCount() const
897 {
898 return ListView_GetSelectedCount(GetHwnd());
899 }
900
901 // Gets the text colour of the listview
902 wxColour wxListCtrl::GetTextColour() const
903 {
904 COLORREF ref = ListView_GetTextColor(GetHwnd());
905 wxColour col(GetRValue(ref), GetGValue(ref), GetBValue(ref));
906 return col;
907 }
908
909 // Sets the text colour of the listview
910 void wxListCtrl::SetTextColour(const wxColour& col)
911 {
912 ListView_SetTextColor(GetHwnd(), PALETTERGB(col.Red(), col.Green(), col.Blue()));
913 }
914
915 // Gets the index of the topmost visible item when in
916 // list or report view
917 long wxListCtrl::GetTopItem() const
918 {
919 return (long) ListView_GetTopIndex(GetHwnd());
920 }
921
922 // Searches for an item, starting from 'item'.
923 // 'geometry' is one of
924 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
925 // 'state' is a state bit flag, one or more of
926 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
927 // item can be -1 to find the first item that matches the
928 // specified flags.
929 // Returns the item or -1 if unsuccessful.
930 long wxListCtrl::GetNextItem(long item, int geom, int state) const
931 {
932 long flags = 0;
933
934 if ( geom == wxLIST_NEXT_ABOVE )
935 flags |= LVNI_ABOVE;
936 if ( geom == wxLIST_NEXT_ALL )
937 flags |= LVNI_ALL;
938 if ( geom == wxLIST_NEXT_BELOW )
939 flags |= LVNI_BELOW;
940 if ( geom == wxLIST_NEXT_LEFT )
941 flags |= LVNI_TOLEFT;
942 if ( geom == wxLIST_NEXT_RIGHT )
943 flags |= LVNI_TORIGHT;
944
945 if ( state & wxLIST_STATE_CUT )
946 flags |= LVNI_CUT;
947 if ( state & wxLIST_STATE_DROPHILITED )
948 flags |= LVNI_DROPHILITED;
949 if ( state & wxLIST_STATE_FOCUSED )
950 flags |= LVNI_FOCUSED;
951 if ( state & wxLIST_STATE_SELECTED )
952 flags |= LVNI_SELECTED;
953
954 return (long) ListView_GetNextItem(GetHwnd(), item, flags);
955 }
956
957
958 wxImageList *wxListCtrl::GetImageList(int which) const
959 {
960 if ( which == wxIMAGE_LIST_NORMAL )
961 {
962 return m_imageListNormal;
963 }
964 else if ( which == wxIMAGE_LIST_SMALL )
965 {
966 return m_imageListSmall;
967 }
968 else if ( which == wxIMAGE_LIST_STATE )
969 {
970 return m_imageListState;
971 }
972 return NULL;
973 }
974
975 void wxListCtrl::SetImageList(wxImageList *imageList, int which)
976 {
977 int flags = 0;
978 if ( which == wxIMAGE_LIST_NORMAL )
979 {
980 flags = LVSIL_NORMAL;
981 if (m_ownsImageListNormal) delete m_imageListNormal;
982 m_imageListNormal = imageList;
983 m_ownsImageListNormal = FALSE;
984 }
985 else if ( which == wxIMAGE_LIST_SMALL )
986 {
987 flags = LVSIL_SMALL;
988 if (m_ownsImageListSmall) delete m_imageListSmall;
989 m_imageListSmall = imageList;
990 m_ownsImageListSmall = FALSE;
991 }
992 else if ( which == wxIMAGE_LIST_STATE )
993 {
994 flags = LVSIL_STATE;
995 if (m_ownsImageListState) delete m_imageListState;
996 m_imageListState = imageList;
997 m_ownsImageListState = FALSE;
998 }
999 ListView_SetImageList(GetHwnd(), (HIMAGELIST) imageList ? imageList->GetHIMAGELIST() : 0, flags);
1000 }
1001
1002 void wxListCtrl::AssignImageList(wxImageList *imageList, int which)
1003 {
1004 SetImageList(imageList, which);
1005 if ( which == wxIMAGE_LIST_NORMAL )
1006 m_ownsImageListNormal = TRUE;
1007 else if ( which == wxIMAGE_LIST_SMALL )
1008 m_ownsImageListSmall = TRUE;
1009 else if ( which == wxIMAGE_LIST_STATE )
1010 m_ownsImageListState = TRUE;
1011 }
1012
1013 // ----------------------------------------------------------------------------
1014 // Operations
1015 // ----------------------------------------------------------------------------
1016
1017 // Arranges the items
1018 bool wxListCtrl::Arrange(int flag)
1019 {
1020 UINT code = 0;
1021 if ( flag == wxLIST_ALIGN_LEFT )
1022 code = LVA_ALIGNLEFT;
1023 else if ( flag == wxLIST_ALIGN_TOP )
1024 code = LVA_ALIGNTOP;
1025 else if ( flag == wxLIST_ALIGN_DEFAULT )
1026 code = LVA_DEFAULT;
1027 else if ( flag == wxLIST_ALIGN_SNAP_TO_GRID )
1028 code = LVA_SNAPTOGRID;
1029
1030 return (ListView_Arrange(GetHwnd(), code) != 0);
1031 }
1032
1033 // Deletes an item
1034 bool wxListCtrl::DeleteItem(long item)
1035 {
1036 return (ListView_DeleteItem(GetHwnd(), (int) item) != 0);
1037 }
1038
1039 // Deletes all items
1040 bool wxListCtrl::DeleteAllItems()
1041 {
1042 return (ListView_DeleteAllItems(GetHwnd()) != 0);
1043 }
1044
1045 // Deletes all items
1046 bool wxListCtrl::DeleteAllColumns()
1047 {
1048 while ( m_colCount > 0 )
1049 {
1050 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
1051 {
1052 wxLogLastError(wxT("ListView_DeleteColumn"));
1053
1054 return FALSE;
1055 }
1056
1057 m_colCount--;
1058 }
1059
1060 wxASSERT_MSG( m_colCount == 0, wxT("no columns should be left") );
1061
1062 return TRUE;
1063 }
1064
1065 // Deletes a column
1066 bool wxListCtrl::DeleteColumn(int col)
1067 {
1068 bool success = (ListView_DeleteColumn(GetHwnd(), col) != 0);
1069
1070 if ( success && (m_colCount > 0) )
1071 m_colCount --;
1072 return success;
1073 }
1074
1075 // Clears items, and columns if there are any.
1076 void wxListCtrl::ClearAll()
1077 {
1078 DeleteAllItems();
1079 if ( m_colCount > 0 )
1080 DeleteAllColumns();
1081 }
1082
1083 wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass)
1084 {
1085 wxASSERT( (textControlClass->IsKindOf(CLASSINFO(wxTextCtrl))) );
1086
1087 // VS: ListView_EditLabel requires that the list has focus.
1088 SetFocus();
1089 HWND hWnd = (HWND) ListView_EditLabel(GetHwnd(), item);
1090
1091 if (m_textCtrl)
1092 {
1093 m_textCtrl->SetHWND(0);
1094 m_textCtrl->UnsubclassWin();
1095 delete m_textCtrl;
1096 m_textCtrl = NULL;
1097 }
1098
1099 m_textCtrl = (wxTextCtrl*) textControlClass->CreateObject();
1100 m_textCtrl->SetHWND((WXHWND) hWnd);
1101 m_textCtrl->SubclassWin((WXHWND) hWnd);
1102
1103 return m_textCtrl;
1104 }
1105
1106 // End label editing, optionally cancelling the edit
1107 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel))
1108 {
1109 wxFAIL_MSG( _T("not implemented") );
1110
1111 return FALSE;
1112 }
1113
1114 // Ensures this item is visible
1115 bool wxListCtrl::EnsureVisible(long item)
1116 {
1117 return ListView_EnsureVisible(GetHwnd(), (int) item, FALSE) != 0;
1118 }
1119
1120 // Find an item whose label matches this string, starting from the item after 'start'
1121 // or the beginning if 'start' is -1.
1122 long wxListCtrl::FindItem(long start, const wxString& str, bool partial)
1123 {
1124 LV_FINDINFO findInfo;
1125
1126 findInfo.flags = LVFI_STRING;
1127 if ( partial )
1128 findInfo.flags |= LVFI_PARTIAL;
1129 findInfo.psz = str;
1130
1131 // ListView_FindItem() excludes the first item from search and to look
1132 // through all the items you need to start from -1 which is unnatural and
1133 // inconsistent with the generic version - so we adjust the index
1134 if (start != -1)
1135 start --;
1136 return ListView_FindItem(GetHwnd(), (int) start, &findInfo);
1137 }
1138
1139 // Find an item whose data matches this data, starting from the item after 'start'
1140 // or the beginning if 'start' is -1.
1141 long wxListCtrl::FindItem(long start, long data)
1142 {
1143 LV_FINDINFO findInfo;
1144
1145 findInfo.flags = LVFI_PARAM;
1146 findInfo.lParam = data;
1147
1148 return ListView_FindItem(GetHwnd(), (int) start, & findInfo);
1149 }
1150
1151 // Find an item nearest this position in the specified direction, starting from
1152 // the item after 'start' or the beginning if 'start' is -1.
1153 long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction)
1154 {
1155 LV_FINDINFO findInfo;
1156
1157 findInfo.flags = LVFI_NEARESTXY;
1158 findInfo.pt.x = pt.x;
1159 findInfo.pt.y = pt.y;
1160 findInfo.vkDirection = VK_RIGHT;
1161
1162 if ( direction == wxLIST_FIND_UP )
1163 findInfo.vkDirection = VK_UP;
1164 else if ( direction == wxLIST_FIND_DOWN )
1165 findInfo.vkDirection = VK_DOWN;
1166 else if ( direction == wxLIST_FIND_LEFT )
1167 findInfo.vkDirection = VK_LEFT;
1168 else if ( direction == wxLIST_FIND_RIGHT )
1169 findInfo.vkDirection = VK_RIGHT;
1170
1171 return ListView_FindItem(GetHwnd(), (int) start, & findInfo);
1172 }
1173
1174 // Determines which item (if any) is at the specified point,
1175 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1176 long wxListCtrl::HitTest(const wxPoint& point, int& flags)
1177 {
1178 LV_HITTESTINFO hitTestInfo;
1179 hitTestInfo.pt.x = (int) point.x;
1180 hitTestInfo.pt.y = (int) point.y;
1181
1182 ListView_HitTest(GetHwnd(), & hitTestInfo);
1183
1184 flags = 0;
1185 if ( hitTestInfo.flags & LVHT_ABOVE )
1186 flags |= wxLIST_HITTEST_ABOVE;
1187 if ( hitTestInfo.flags & LVHT_BELOW )
1188 flags |= wxLIST_HITTEST_BELOW;
1189 if ( hitTestInfo.flags & LVHT_NOWHERE )
1190 flags |= wxLIST_HITTEST_NOWHERE;
1191 if ( hitTestInfo.flags & LVHT_ONITEMICON )
1192 flags |= wxLIST_HITTEST_ONITEMICON;
1193 if ( hitTestInfo.flags & LVHT_ONITEMLABEL )
1194 flags |= wxLIST_HITTEST_ONITEMLABEL;
1195 if ( hitTestInfo.flags & LVHT_ONITEMSTATEICON )
1196 flags |= wxLIST_HITTEST_ONITEMSTATEICON;
1197 if ( hitTestInfo.flags & LVHT_TOLEFT )
1198 flags |= wxLIST_HITTEST_TOLEFT;
1199 if ( hitTestInfo.flags & LVHT_TORIGHT )
1200 flags |= wxLIST_HITTEST_TORIGHT;
1201
1202 return (long) hitTestInfo.iItem;
1203 }
1204
1205 // Inserts an item, returning the index of the new item if successful,
1206 // -1 otherwise.
1207 long wxListCtrl::InsertItem(wxListItem& info)
1208 {
1209 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1210
1211 LV_ITEM item;
1212 wxConvertToMSWListItem(this, info, item);
1213
1214 // check whether it has any custom attributes
1215 if ( info.HasAttributes() )
1216 {
1217
1218 wxListItemAttr *attr;
1219 attr = (wxListItemAttr*) m_attrs.Get(item.iItem);
1220
1221 if (attr == NULL)
1222
1223 m_attrs.Put(item.iItem, (wxObject *)new wxListItemAttr(*info.GetAttributes()));
1224
1225 else *attr = *info.GetAttributes();
1226
1227 m_hasAnyAttr = TRUE;
1228 }
1229
1230 return (long) ListView_InsertItem(GetHwnd(), & item);
1231 }
1232
1233 long wxListCtrl::InsertItem(long index, const wxString& label)
1234 {
1235 wxListItem info;
1236 info.m_text = label;
1237 info.m_mask = wxLIST_MASK_TEXT;
1238 info.m_itemId = index;
1239 return InsertItem(info);
1240 }
1241
1242 // Inserts an image item
1243 long wxListCtrl::InsertItem(long index, int imageIndex)
1244 {
1245 wxListItem info;
1246 info.m_image = imageIndex;
1247 info.m_mask = wxLIST_MASK_IMAGE;
1248 info.m_itemId = index;
1249 return InsertItem(info);
1250 }
1251
1252 // Inserts an image/string item
1253 long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex)
1254 {
1255 wxListItem info;
1256 info.m_image = imageIndex;
1257 info.m_text = label;
1258 info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT;
1259 info.m_itemId = index;
1260 return InsertItem(info);
1261 }
1262
1263 // For list view mode (only), inserts a column.
1264 long wxListCtrl::InsertColumn(long col, wxListItem& item)
1265 {
1266 LV_COLUMN lvCol;
1267 lvCol.mask = 0;
1268 lvCol.fmt = 0;
1269 lvCol.pszText = NULL;
1270
1271 if ( item.m_mask & wxLIST_MASK_TEXT )
1272 {
1273 lvCol.mask |= LVCF_TEXT;
1274 lvCol.pszText = WXSTRINGCAST item.m_text;
1275 lvCol.cchTextMax = 0; // Ignored
1276 }
1277 if ( item.m_mask & wxLIST_MASK_FORMAT )
1278 {
1279 lvCol.mask |= LVCF_FMT;
1280
1281 if ( item.m_format == wxLIST_FORMAT_LEFT )
1282 lvCol.fmt = LVCFMT_LEFT;
1283 if ( item.m_format == wxLIST_FORMAT_RIGHT )
1284 lvCol.fmt = LVCFMT_RIGHT;
1285 if ( item.m_format == wxLIST_FORMAT_CENTRE )
1286 lvCol.fmt = LVCFMT_CENTER;
1287 }
1288
1289 lvCol.mask |= LVCF_WIDTH;
1290 if ( item.m_mask & wxLIST_MASK_WIDTH )
1291 {
1292 if ( item.m_width == wxLIST_AUTOSIZE)
1293 lvCol.cx = LVSCW_AUTOSIZE;
1294 else if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER)
1295 lvCol.cx = LVSCW_AUTOSIZE_USEHEADER;
1296 else
1297 lvCol.cx = item.m_width;
1298 }
1299 else
1300 {
1301 // always give some width to the new column: this one is compatible
1302 // with wxGTK
1303 lvCol.cx = 80;
1304 }
1305
1306 lvCol.mask |= LVCF_SUBITEM;
1307 lvCol.iSubItem = col;
1308
1309 bool success = ListView_InsertColumn(GetHwnd(), col, & lvCol) != -1;
1310 if ( success )
1311 {
1312 m_colCount++;
1313 }
1314 else
1315 {
1316 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1317 lvCol.pszText);
1318 }
1319
1320 return success;
1321 }
1322
1323 long wxListCtrl::InsertColumn(long col,
1324 const wxString& heading,
1325 int format,
1326 int width)
1327 {
1328 wxListItem item;
1329 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
1330 item.m_text = heading;
1331 if ( width > -1 )
1332 {
1333 item.m_mask |= wxLIST_MASK_WIDTH;
1334 item.m_width = width;
1335 }
1336 item.m_format = format;
1337
1338 return InsertColumn(col, item);
1339 }
1340
1341 // Scrolls the list control. If in icon, small icon or report view mode,
1342 // x specifies the number of pixels to scroll. If in list view mode, x
1343 // specifies the number of columns to scroll.
1344 // If in icon, small icon or list view mode, y specifies the number of pixels
1345 // to scroll. If in report view mode, y specifies the number of lines to scroll.
1346 bool wxListCtrl::ScrollList(int dx, int dy)
1347 {
1348 return (ListView_Scroll(GetHwnd(), dx, dy) != 0);
1349 }
1350
1351 // Sort items.
1352
1353 // fn is a function which takes 3 long arguments: item1, item2, data.
1354 // item1 is the long data associated with a first item (NOT the index).
1355 // item2 is the long data associated with a second item (NOT the index).
1356 // data is the same value as passed to SortItems.
1357 // The return value is a negative number if the first item should precede the second
1358 // item, a positive number of the second item should precede the first,
1359 // or zero if the two items are equivalent.
1360
1361 // data is arbitrary data to be passed to the sort function.
1362 bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data)
1363 {
1364 return (ListView_SortItems(GetHwnd(), (PFNLVCOMPARE) fn, data) != 0);
1365 }
1366
1367 // ----------------------------------------------------------------------------
1368 // message processing
1369 // ----------------------------------------------------------------------------
1370
1371 bool wxListCtrl::MSWCommand(WXUINT cmd, WXWORD id)
1372 {
1373 if (cmd == EN_UPDATE)
1374 {
1375 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, id);
1376 event.SetEventObject( this );
1377 ProcessCommand(event);
1378 return TRUE;
1379 }
1380 else if (cmd == EN_KILLFOCUS)
1381 {
1382 wxCommandEvent event(wxEVT_KILL_FOCUS, id);
1383 event.SetEventObject( this );
1384 ProcessCommand(event);
1385 return TRUE;
1386 }
1387 else
1388 return FALSE;
1389 }
1390
1391 bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
1392 {
1393 // prepare the event
1394 // -----------------
1395
1396 wxListEvent event(wxEVT_NULL, m_windowId);
1397 wxEventType eventType = wxEVT_NULL;
1398
1399 NMHDR *nmhdr = (NMHDR *)lParam;
1400
1401 // almost all messages use NM_LISTVIEW
1402 NM_LISTVIEW *nmLV = (NM_LISTVIEW *)nmhdr;
1403
1404 // this is true for almost all events
1405 event.m_item.m_data = nmLV->lParam;
1406
1407 switch ( nmhdr->code )
1408 {
1409 case LVN_BEGINRDRAG:
1410 eventType = wxEVT_COMMAND_LIST_BEGIN_RDRAG;
1411 // fall through
1412
1413 case LVN_BEGINDRAG:
1414 if ( eventType == wxEVT_NULL )
1415 {
1416 eventType = wxEVT_COMMAND_LIST_BEGIN_DRAG;
1417 }
1418
1419 event.m_itemIndex = nmLV->iItem;
1420 event.m_pointDrag.x = nmLV->ptAction.x;
1421 event.m_pointDrag.y = nmLV->ptAction.y;
1422 break;
1423
1424 case LVN_BEGINLABELEDIT:
1425 {
1426 eventType = wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT;
1427 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1428 wxConvertFromMSWListItem(GetHwnd(), event.m_item, info->item);
1429 event.m_itemIndex = event.m_item.m_itemId;
1430 }
1431 break;
1432
1433 case LVN_COLUMNCLICK:
1434 eventType = wxEVT_COMMAND_LIST_COL_CLICK;
1435 event.m_itemIndex = -1;
1436 event.m_col = nmLV->iSubItem;
1437 break;
1438
1439 case LVN_DELETEALLITEMS:
1440 eventType = wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS;
1441 event.m_itemIndex = -1;
1442
1443 FreeAllAttrs();
1444
1445 break;
1446
1447 case LVN_DELETEITEM:
1448 eventType = wxEVT_COMMAND_LIST_DELETE_ITEM;
1449 event.m_itemIndex = nmLV->iItem;
1450
1451 if ( m_hasAnyAttr )
1452 {
1453 delete (wxListItemAttr *)m_attrs.Delete(nmLV->iItem);
1454 }
1455 break;
1456
1457 case LVN_ENDLABELEDIT:
1458 {
1459 eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT;
1460 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1461 wxConvertFromMSWListItem(GetHwnd(), event.m_item, info->item);
1462 if ( info->item.pszText == NULL || info->item.iItem == -1 )
1463 return FALSE;
1464
1465 event.m_itemIndex = event.m_item.m_itemId;
1466 }
1467 break;
1468
1469 case LVN_SETDISPINFO:
1470 {
1471 eventType = wxEVT_COMMAND_LIST_SET_INFO;
1472 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1473 wxConvertFromMSWListItem(GetHwnd(), event.m_item, info->item);
1474 }
1475 break;
1476
1477 case LVN_INSERTITEM:
1478 eventType = wxEVT_COMMAND_LIST_INSERT_ITEM;
1479 event.m_itemIndex = nmLV->iItem;
1480 break;
1481
1482 case LVN_ITEMCHANGED:
1483 // This needs to be sent to wxListCtrl as a rather more concrete
1484 // event. For now, just detect a selection or deselection.
1485 if ( (nmLV->uNewState & LVIS_SELECTED) && !(nmLV->uOldState & LVIS_SELECTED) )
1486 {
1487 eventType = wxEVT_COMMAND_LIST_ITEM_SELECTED;
1488 event.m_itemIndex = nmLV->iItem;
1489 }
1490 else if ( !(nmLV->uNewState & LVIS_SELECTED) && (nmLV->uOldState & LVIS_SELECTED) )
1491 {
1492 eventType = wxEVT_COMMAND_LIST_ITEM_DESELECTED;
1493 event.m_itemIndex = nmLV->iItem;
1494 }
1495 else
1496 {
1497 return FALSE;
1498 }
1499 break;
1500
1501 case LVN_KEYDOWN:
1502 {
1503 LV_KEYDOWN *info = (LV_KEYDOWN *)lParam;
1504 WORD wVKey = info->wVKey;
1505
1506 // get the current selection
1507 long lItem = GetNextItem(-1,
1508 wxLIST_NEXT_ALL,
1509 wxLIST_STATE_SELECTED);
1510
1511 // <Enter> or <Space> activate the selected item if any (but
1512 // not with Shift and/or Ctrl as then they have a predefined
1513 // meaning for the list view)
1514 if ( lItem != -1 &&
1515 (wVKey == VK_RETURN || wVKey == VK_SPACE) &&
1516 !(wxIsShiftDown() || wxIsCtrlDown()) )
1517 {
1518 eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
1519 }
1520 else
1521 {
1522 eventType = wxEVT_COMMAND_LIST_KEY_DOWN;
1523 event.m_code = wxCharCodeMSWToWX(wVKey);
1524 }
1525
1526 event.m_itemIndex =
1527 event.m_item.m_itemId = lItem;
1528
1529 if ( lItem != -1 )
1530 {
1531 // fill the other fields too
1532 event.m_item.m_text = GetItemText(lItem);
1533 event.m_item.m_data = GetItemData(lItem);
1534 }
1535 }
1536 break;
1537
1538 case NM_DBLCLK:
1539 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1540 // anything else
1541 if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
1542 {
1543 return TRUE;
1544 }
1545
1546 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
1547 // if it happened on an item (and not on empty place)
1548 if ( nmLV->iItem == -1 )
1549 {
1550 // not on item
1551 return FALSE;
1552 }
1553
1554 eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
1555 event.m_itemIndex = nmLV->iItem;
1556 event.m_item.m_text = GetItemText(nmLV->iItem);
1557 event.m_item.m_data = GetItemData(nmLV->iItem);
1558 break;
1559
1560 case NM_RCLICK:
1561 /* TECH NOTE: NM_RCLICK isn't really good enough here. We want to
1562 subclass and check for the actual WM_RBUTTONDOWN message,
1563 because NM_RCLICK waits for the WM_RBUTTONUP message as well
1564 before firing off. We want to have notify events for both down
1565 -and- up. */
1566 {
1567 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
1568 // don't do anything else
1569 if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
1570 {
1571 return TRUE;
1572 }
1573
1574 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1575 LV_HITTESTINFO lvhti;
1576 wxZeroMemory(lvhti);
1577
1578 ::GetCursorPos(&(lvhti.pt));
1579 ::ScreenToClient(GetHwnd(),&(lvhti.pt));
1580 if ( ListView_HitTest(GetHwnd(),&lvhti) != -1 )
1581 {
1582 if ( lvhti.flags & LVHT_ONITEM )
1583 {
1584 eventType = wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK;
1585 event.m_itemIndex = lvhti.iItem;
1586 event.m_pointDrag.x = lvhti.pt.x;
1587 event.m_pointDrag.y = lvhti.pt.y;
1588 }
1589 }
1590 }
1591 break;
1592
1593 #if 0
1594 case NM_MCLICK: // ***** THERE IS NO NM_MCLICK. Subclass anyone? ******
1595 {
1596 // if the user processes it in wxEVT_COMMAND_MIDDLE_CLICK(), don't do
1597 // anything else
1598 if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
1599 {
1600 return TRUE;
1601 }
1602
1603 // else translate it into wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK event
1604 eventType = wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK;
1605 NMITEMACTIVATE* hdr = (NMITEMACTIVATE*)lParam;
1606 event.m_itemIndex = hdr->iItem;
1607 }
1608 break;
1609 #endif // 0
1610
1611 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300
1612 case NM_CUSTOMDRAW:
1613 *result = OnCustomDraw(lParam);
1614
1615 return TRUE;
1616 #endif // _WIN32_IE >= 0x300
1617
1618 case LVN_GETDISPINFO:
1619 if ( IsVirtual() )
1620 {
1621 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1622
1623 LV_ITEM& lvi = info->item;
1624 long item = lvi.iItem;
1625
1626 if ( lvi.mask & LVIF_TEXT )
1627 {
1628 wxString text = OnGetItemText(item, lvi.iSubItem);
1629 wxStrncpy(lvi.pszText, text, lvi.cchTextMax);
1630 }
1631
1632 if ( lvi.mask & LVIF_IMAGE )
1633 {
1634 lvi.iImage = OnGetItemImage(item);
1635 }
1636
1637 // a little dose of healthy paranoia: as we never use
1638 // LVM_SETCALLBACKMASK we're not supposed to get these ones
1639 wxASSERT_MSG( !(lvi.mask & LVIF_STATE),
1640 _T("we don't support state callbacks yet!") );
1641
1642 return TRUE;
1643 }
1644 // fall through
1645
1646 default:
1647 return wxControl::MSWOnNotify(idCtrl, lParam, result);
1648 }
1649
1650 // process the event
1651 // -----------------
1652
1653 event.SetEventObject( this );
1654 event.SetEventType(eventType);
1655
1656 if ( !GetEventHandler()->ProcessEvent(event) )
1657 return FALSE;
1658
1659 // post processing
1660 // ---------------
1661
1662 switch ( nmhdr->code )
1663 {
1664 case LVN_DELETEALLITEMS:
1665 // always return TRUE to suppress all additional LVN_DELETEITEM
1666 // notifications - this makes deleting all items from a list ctrl
1667 // much faster
1668 *result = TRUE;
1669
1670 return TRUE;
1671
1672 case LVN_ENDLABELEDIT:
1673 {
1674 *result = event.IsAllowed();
1675 return TRUE;
1676 }
1677 }
1678
1679 *result = !event.IsAllowed();
1680
1681 return TRUE;
1682 }
1683
1684 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300
1685
1686 WXLPARAM wxListCtrl::OnCustomDraw(WXLPARAM lParam)
1687 {
1688 LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
1689 NMCUSTOMDRAW& nmcd = lplvcd->nmcd;
1690 switch ( nmcd.dwDrawStage )
1691 {
1692 case CDDS_PREPAINT:
1693 // if we've got any items with non standard attributes,
1694 // notify us before painting each item
1695 //
1696 // for virtual controls, always suppose that we have attributes as
1697 // there is no way to check for this
1698 return IsVirtual() || m_hasAnyAttr ? CDRF_NOTIFYITEMDRAW
1699 : CDRF_DODEFAULT;
1700
1701 case CDDS_ITEMPREPAINT:
1702 {
1703 size_t item = (size_t)nmcd.dwItemSpec;
1704 if ( item >= (size_t)GetItemCount() )
1705 {
1706 // we get this message with item == 0 for an empty control,
1707 // we must ignore it as calling OnGetItemAttr() would be
1708 // wrong
1709 return CDRF_DODEFAULT;
1710 }
1711
1712 wxListItemAttr *attr =
1713 IsVirtual() ? OnGetItemAttr(item)
1714 : (wxListItemAttr *)m_attrs.Get(item);
1715
1716 if ( !attr )
1717 {
1718 // nothing to do for this item
1719 return CDRF_DODEFAULT;
1720 }
1721
1722 HFONT hFont;
1723 wxColour colText, colBack;
1724 if ( attr->HasFont() )
1725 {
1726 wxFont font = attr->GetFont();
1727 hFont = (HFONT)font.GetResourceHandle();
1728 }
1729 else
1730 {
1731 hFont = 0;
1732 }
1733
1734 if ( attr->HasTextColour() )
1735 {
1736 colText = attr->GetTextColour();
1737 }
1738 else
1739 {
1740 colText = GetTextColour();
1741 }
1742
1743 if ( attr->HasBackgroundColour() )
1744 {
1745 colBack = attr->GetBackgroundColour();
1746 }
1747 else
1748 {
1749 colBack = GetBackgroundColour();
1750 }
1751
1752 lplvcd->clrText = wxColourToRGB(colText);
1753 lplvcd->clrTextBk = wxColourToRGB(colBack);
1754
1755 // note that if we wanted to set colours for
1756 // individual columns (subitems), we would have
1757 // returned CDRF_NOTIFYSUBITEMREDRAW from here
1758 if ( hFont )
1759 {
1760 ::SelectObject(nmcd.hdc, hFont);
1761
1762 return CDRF_NEWFONT;
1763 }
1764 }
1765 // fall through to return CDRF_DODEFAULT
1766
1767 default:
1768 return CDRF_DODEFAULT;
1769 }
1770 }
1771
1772 #endif // NM_CUSTOMDRAW supported
1773
1774 // Necessary for drawing hrules and vrules, if specified
1775 void wxListCtrl::OnPaint(wxPaintEvent& event)
1776 {
1777 wxPaintDC dc(this);
1778
1779 wxControl::OnPaint(event);
1780
1781 // Reset the device origin since it may have been set
1782 dc.SetDeviceOrigin(0, 0);
1783
1784 bool drawHRules = ((GetWindowStyle() & wxLC_HRULES) != 0);
1785 bool drawVRules = ((GetWindowStyle() & wxLC_VRULES) != 0);
1786
1787 if (!drawHRules && !drawVRules)
1788 return;
1789 if ((GetWindowStyle() & wxLC_REPORT) == 0)
1790 return;
1791
1792 wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
1793 dc.SetPen(pen);
1794 dc.SetBrush(* wxTRANSPARENT_BRUSH);
1795
1796 wxSize clientSize = GetClientSize();
1797 wxRect itemRect;
1798 int cy=0;
1799
1800 int itemCount = GetItemCount();
1801 int i;
1802 for (i = 0; i < itemCount; i++)
1803 {
1804 if (GetItemRect(i, itemRect))
1805 {
1806 cy = itemRect.GetTop();
1807 if (i != 0) // Don't draw the first one
1808 {
1809 dc.DrawLine(0, cy, clientSize.x, cy);
1810 }
1811 // Draw last line
1812 if (i == (GetItemCount() - 1))
1813 {
1814 cy = itemRect.GetBottom();
1815 dc.DrawLine(0, cy, clientSize.x, cy);
1816 }
1817 }
1818 }
1819 i = (GetItemCount() - 1);
1820 if (drawVRules && (i > -1))
1821 {
1822 wxRect firstItemRect;
1823 GetItemRect(0, firstItemRect);
1824
1825 if (GetItemRect(i, itemRect))
1826 {
1827 int col;
1828 int x = itemRect.GetX();
1829 for (col = 0; col < GetColumnCount(); col++)
1830 {
1831 int colWidth = GetColumnWidth(col);
1832 x += colWidth ;
1833 dc.DrawLine(x, firstItemRect.GetY() - 2, x, itemRect.GetBottom());
1834 }
1835 }
1836 }
1837 }
1838
1839 // ----------------------------------------------------------------------------
1840 // virtual list controls
1841 // ----------------------------------------------------------------------------
1842
1843 wxString wxListCtrl::OnGetItemText(long item, long col) const
1844 {
1845 // this is a pure virtual function, in fact - which is not really pure
1846 // because the controls which are not virtual don't need to implement it
1847 wxFAIL_MSG( _T("not supposed to be called") );
1848
1849 return wxEmptyString;
1850 }
1851
1852 int wxListCtrl::OnGetItemImage(long item) const
1853 {
1854 // same as above
1855 wxFAIL_MSG( _T("not supposed to be called") );
1856
1857 return -1;
1858 }
1859
1860 wxListItemAttr *wxListCtrl::OnGetItemAttr(long item) const
1861 {
1862 wxASSERT_MSG( item >= 0 && item < GetItemCount(),
1863 _T("invalid item index in OnGetItemAttr()") );
1864
1865 // no attributes by default
1866 return NULL;
1867 }
1868
1869 void wxListCtrl::SetItemCount(long count)
1870 {
1871 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
1872
1873 if ( !::SendMessage(GetHwnd(), LVM_SETITEMCOUNT, (WPARAM)count, 0) )
1874 {
1875 wxLogLastError(_T("ListView_SetItemCount"));
1876 }
1877 }
1878
1879 void wxListCtrl::RefreshItem(long item)
1880 {
1881 if ( !ListView_Update(GetHwnd(), item) )
1882 {
1883 wxLogLastError(_T("ListView_Update"));
1884 }
1885 }
1886
1887 void wxListCtrl::RefreshItems(long itemFrom, long itemTo)
1888 {
1889 for ( long item = itemFrom; item <= itemTo; item++ )
1890 {
1891 RefreshItem(item);
1892 }
1893 }
1894
1895 // ----------------------------------------------------------------------------
1896 // wxListItem
1897 // ----------------------------------------------------------------------------
1898
1899 // List item structure
1900 wxListItem::wxListItem()
1901 {
1902 m_mask = 0;
1903 m_itemId = 0;
1904 m_col = 0;
1905 m_state = 0;
1906 m_stateMask = 0;
1907 m_image = 0;
1908 m_data = 0;
1909
1910 m_format = wxLIST_FORMAT_CENTRE;
1911 m_width = 0;
1912
1913 m_attr = NULL;
1914 }
1915
1916 void wxListItem::Clear()
1917 {
1918 m_mask = 0;
1919 m_itemId = 0;
1920 m_col = 0;
1921 m_state = 0;
1922 m_stateMask = 0;
1923 m_image = 0;
1924 m_data = 0;
1925 m_format = wxLIST_FORMAT_CENTRE;
1926 m_width = 0;
1927 m_text = wxEmptyString;
1928
1929 if (m_attr) delete m_attr;
1930 m_attr = NULL;
1931 }
1932
1933 void wxListItem::ClearAttributes()
1934 {
1935 if (m_attr) delete m_attr;
1936 m_attr = NULL;
1937 }
1938
1939 static void wxConvertFromMSWListItem(HWND hwndListCtrl,
1940 wxListItem& info,
1941 LV_ITEM& lvItem)
1942 {
1943 info.m_data = lvItem.lParam;
1944 info.m_mask = 0;
1945 info.m_state = 0;
1946 info.m_stateMask = 0;
1947 info.m_itemId = lvItem.iItem;
1948
1949 long oldMask = lvItem.mask;
1950
1951 bool needText = FALSE;
1952 if (hwndListCtrl != 0)
1953 {
1954 if ( lvItem.mask & LVIF_TEXT )
1955 needText = FALSE;
1956 else
1957 needText = TRUE;
1958
1959 if ( needText )
1960 {
1961 lvItem.pszText = new wxChar[513];
1962 lvItem.cchTextMax = 512;
1963 }
1964 lvItem.mask |= LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
1965 ::SendMessage(hwndListCtrl, LVM_GETITEM, 0, (LPARAM)& lvItem);
1966 }
1967
1968 if ( lvItem.mask & LVIF_STATE )
1969 {
1970 info.m_mask |= wxLIST_MASK_STATE;
1971
1972 if ( lvItem.stateMask & LVIS_CUT)
1973 {
1974 info.m_stateMask |= wxLIST_STATE_CUT;
1975 if ( lvItem.state & LVIS_CUT )
1976 info.m_state |= wxLIST_STATE_CUT;
1977 }
1978 if ( lvItem.stateMask & LVIS_DROPHILITED)
1979 {
1980 info.m_stateMask |= wxLIST_STATE_DROPHILITED;
1981 if ( lvItem.state & LVIS_DROPHILITED )
1982 info.m_state |= wxLIST_STATE_DROPHILITED;
1983 }
1984 if ( lvItem.stateMask & LVIS_FOCUSED)
1985 {
1986 info.m_stateMask |= wxLIST_STATE_FOCUSED;
1987 if ( lvItem.state & LVIS_FOCUSED )
1988 info.m_state |= wxLIST_STATE_FOCUSED;
1989 }
1990 if ( lvItem.stateMask & LVIS_SELECTED)
1991 {
1992 info.m_stateMask |= wxLIST_STATE_SELECTED;
1993 if ( lvItem.state & LVIS_SELECTED )
1994 info.m_state |= wxLIST_STATE_SELECTED;
1995 }
1996 }
1997
1998 if ( lvItem.mask & LVIF_TEXT )
1999 {
2000 info.m_mask |= wxLIST_MASK_TEXT;
2001 info.m_text = lvItem.pszText;
2002 }
2003 if ( lvItem.mask & LVIF_IMAGE )
2004 {
2005 info.m_mask |= wxLIST_MASK_IMAGE;
2006 info.m_image = lvItem.iImage;
2007 }
2008 if ( lvItem.mask & LVIF_PARAM )
2009 info.m_mask |= wxLIST_MASK_DATA;
2010 if ( lvItem.mask & LVIF_DI_SETITEM )
2011 info.m_mask |= wxLIST_SET_ITEM;
2012 info.m_col = lvItem.iSubItem;
2013
2014 if (needText)
2015 {
2016 if (lvItem.pszText)
2017 delete[] lvItem.pszText;
2018 }
2019 lvItem.mask = oldMask;
2020 }
2021
2022 static void wxConvertToMSWFlags(long state, long stateMask, LV_ITEM& lvItem)
2023 {
2024 if (stateMask & wxLIST_STATE_CUT)
2025 {
2026 lvItem.stateMask |= LVIS_CUT;
2027 if (state & wxLIST_STATE_CUT)
2028 lvItem.state |= LVIS_CUT;
2029 }
2030 if (stateMask & wxLIST_STATE_DROPHILITED)
2031 {
2032 lvItem.stateMask |= LVIS_DROPHILITED;
2033 if (state & wxLIST_STATE_DROPHILITED)
2034 lvItem.state |= LVIS_DROPHILITED;
2035 }
2036 if (stateMask & wxLIST_STATE_FOCUSED)
2037 {
2038 lvItem.stateMask |= LVIS_FOCUSED;
2039 if (state & wxLIST_STATE_FOCUSED)
2040 lvItem.state |= LVIS_FOCUSED;
2041 }
2042 if (stateMask & wxLIST_STATE_SELECTED)
2043 {
2044 lvItem.stateMask |= LVIS_SELECTED;
2045 if (state & wxLIST_STATE_SELECTED)
2046 lvItem.state |= LVIS_SELECTED;
2047 }
2048 }
2049
2050 static void wxConvertToMSWListItem(const wxListCtrl *ctrl,
2051 const wxListItem& info,
2052 LV_ITEM& lvItem)
2053 {
2054 lvItem.iItem = (int) info.m_itemId;
2055
2056 lvItem.iImage = info.m_image;
2057 lvItem.lParam = info.m_data;
2058 lvItem.stateMask = 0;
2059 lvItem.state = 0;
2060 lvItem.mask = 0;
2061 lvItem.iSubItem = info.m_col;
2062
2063 if (info.m_mask & wxLIST_MASK_STATE)
2064 {
2065 lvItem.mask |= LVIF_STATE;
2066
2067 wxConvertToMSWFlags(info.m_state, info.m_stateMask, lvItem);
2068 }
2069
2070 if (info.m_mask & wxLIST_MASK_TEXT)
2071 {
2072 lvItem.mask |= LVIF_TEXT;
2073 if ( ctrl->GetWindowStyleFlag() & wxLC_USER_TEXT )
2074 {
2075 lvItem.pszText = LPSTR_TEXTCALLBACK;
2076 }
2077 else
2078 {
2079 // pszText is not const, hence the cast
2080 lvItem.pszText = (wxChar *)info.m_text.c_str();
2081 if ( lvItem.pszText )
2082 lvItem.cchTextMax = info.m_text.Length();
2083 else
2084 lvItem.cchTextMax = 0;
2085 }
2086 }
2087 if (info.m_mask & wxLIST_MASK_IMAGE)
2088 lvItem.mask |= LVIF_IMAGE;
2089 if (info.m_mask & wxLIST_MASK_DATA)
2090 lvItem.mask |= LVIF_PARAM;
2091 }
2092
2093 // ----------------------------------------------------------------------------
2094 // List event
2095 // ----------------------------------------------------------------------------
2096
2097 IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
2098
2099 wxListEvent::wxListEvent(wxEventType commandType, int id)
2100 : wxNotifyEvent(commandType, id)
2101 {
2102 m_code = 0;
2103 m_itemIndex = 0;
2104 m_oldItemIndex = 0;
2105 m_col = 0;
2106 m_cancelled = FALSE;
2107 }
2108
2109 #endif // wxUSE_LISTCTRL