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