]> git.saurik.com Git - wxWidgets.git/blob - src/msw/listctrl.cpp
wxFileConfig ctor now (again) uses the files in the correct locations if the
[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 #ifdef __GNUG__
13 #pragma implementation "listctrl.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx.h"
25 #endif
26
27 #if defined(__WIN95__)
28
29 #include "wx/listctrl.h"
30 #include "wx/log.h"
31
32 #include "wx/msw/private.h"
33
34 #ifndef __GNUWIN32__
35 #include <commctrl.h>
36 #endif
37
38 #ifdef __GNUWIN32__
39 #include "wx/msw/gnuwin32/extra.h"
40 #endif
41
42 static void wxConvertToMSWListItem(const wxListCtrl *ctrl, wxListItem& info, LV_ITEM& tvItem);
43 static void wxConvertFromMSWListItem(const wxListCtrl *ctrl, wxListItem& info, LV_ITEM& tvItem, HWND getFullInfo = 0);
44
45 #if !USE_SHARED_LIBRARY
46 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
47 IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
48
49 #endif
50
51 wxListCtrl::wxListCtrl(void)
52 {
53 m_imageListNormal = NULL;
54 m_imageListSmall = NULL;
55 m_imageListState = NULL;
56 m_baseStyle = 0;
57 m_colCount = 0;
58 m_textCtrl = NULL;
59 }
60
61 bool wxListCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
62 long style, const wxValidator& validator, const wxString& name)
63 {
64 m_imageListNormal = NULL;
65 m_imageListSmall = NULL;
66 m_imageListState = NULL;
67 m_textCtrl = NULL;
68 m_colCount = 0;
69
70 SetValidator(validator);
71 SetName(name);
72
73 int x = pos.x;
74 int y = pos.y;
75 int width = size.x;
76 int height = size.y;
77
78 m_windowStyle = style;
79
80 SetParent(parent);
81
82 if (width <= 0)
83 width = 100;
84 if (height <= 0)
85 height = 30;
86 if (x < 0)
87 x = 0;
88 if (y < 0)
89 y = 0;
90
91 m_windowId = (id == -1) ? NewControlId() : id;
92
93 DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP;
94
95 bool want3D;
96 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ;
97
98 // Even with extended styles, need to combine with WS_BORDER
99 // for them to look right.
100 if (want3D || (m_windowStyle & wxSIMPLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) ||
101 (m_windowStyle & wxSUNKEN_BORDER) || (m_windowStyle & wxDOUBLE_BORDER))
102 wstyle |= WS_BORDER;
103
104 wstyle |= LVS_SHAREIMAGELISTS;
105 m_baseStyle = wstyle;
106
107 long oldStyle = 0; // Dummy
108 wstyle |= ConvertToMSWStyle(oldStyle, m_windowStyle);
109
110 // Create the ListView control.
111 m_hWnd = (WXHWND)CreateWindowEx(exStyle,
112 WC_LISTVIEW,
113 "",
114 wstyle,
115 x, y, width, height,
116 (HWND) parent->GetHWND(),
117 (HMENU)m_windowId,
118 wxGetInstance(),
119 NULL);
120
121 if ( !m_hWnd ) {
122 wxLogError("Can't create list control window.");
123
124 return FALSE;
125 }
126
127 wxSystemSettings settings;
128 SetBackgroundColour(settings.GetSystemColour(wxSYS_COLOUR_WINDOW));
129 SetForegroundColour(parent->GetDefaultForegroundColour());
130
131 if (parent) parent->AddChild(this);
132
133 SubclassWin((WXHWND) m_hWnd);
134
135 return TRUE;
136 }
137
138 wxListCtrl::~wxListCtrl(void)
139 {
140 if (m_textCtrl)
141 {
142 m_textCtrl->UnsubclassWin();
143 m_textCtrl->SetHWND(0);
144 delete m_textCtrl;
145 m_textCtrl = NULL;
146 }
147 }
148
149 // Add or remove a single window style
150 void wxListCtrl::SetSingleStyle(long style, bool add)
151 {
152 long flag = GetWindowStyleFlag();
153
154 // Get rid of conflicting styles
155 if ( add )
156 {
157 if ( style & wxLC_MASK_TYPE)
158 flag = flag & ~wxLC_MASK_TYPE ;
159 if ( style & wxLC_MASK_ALIGN )
160 flag = flag & ~wxLC_MASK_ALIGN ;
161 if ( style & wxLC_MASK_SORT )
162 flag = flag & ~wxLC_MASK_SORT ;
163 }
164
165 if ( flag & style )
166 {
167 if ( !add )
168 flag -= style;
169 }
170 else
171 {
172 if ( add )
173 {
174 flag |= style;
175 }
176 }
177
178 m_windowStyle = flag;
179
180 RecreateWindow();
181 }
182
183 // Set the whole window style
184 void wxListCtrl::SetWindowStyleFlag(long flag)
185 {
186 m_windowStyle = flag;
187
188 RecreateWindow();
189 }
190
191 void wxListCtrl::RecreateWindow(void)
192 {
193 if ( GetHWND() )
194 {
195 long oldStyle = 0;
196 long style = ConvertToMSWStyle(oldStyle, m_windowStyle);
197 style |= m_baseStyle;
198 // ::SetWindowLong((HWND) GetHWND(), GWL_STYLE, style);
199
200 // The following recreation of the window appears to be necessary
201 // because SetWindowLong doesn't seem to do it.
202
203 int x, y, width, height;
204 GetPosition(&x, &y);
205 GetSize(&width, &height);
206
207 UnsubclassWin();
208 ::DestroyWindow((HWND) GetHWND());
209
210 // Experimental
211 // Recreate the ListView control: unfortunately I can't
212 // make it work by using SetWindowLong.
213 bool want3D;
214 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ;
215 HWND hWndListControl = CreateWindowEx(exStyle,
216 WC_LISTVIEW,
217 "",
218 style,
219 x, y, width, height,
220 (HWND) GetParent()->GetHWND(),
221 (HMENU)m_windowId,
222 wxGetInstance(),
223 NULL );
224
225 m_hWnd = (WXHWND) hWndListControl;
226 SubclassWin((WXHWND) m_hWnd);
227
228 if ( m_imageListNormal )
229 SetImageList(m_imageListNormal, wxIMAGE_LIST_NORMAL);
230 if ( m_imageListSmall )
231 SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL);
232 if ( m_imageListState )
233 SetImageList(m_imageListState, wxIMAGE_LIST_STATE);
234 }
235 }
236
237 // Can be just a single style, or a bitlist
238 long wxListCtrl::ConvertToMSWStyle(long& oldStyle, long style) const
239 {
240 long wstyle = 0;
241 if ( style & wxLC_ICON )
242 {
243 if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON )
244 oldStyle -= LVS_SMALLICON;
245 if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT )
246 oldStyle -= LVS_REPORT;
247 if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST )
248 oldStyle -= LVS_LIST;
249 wstyle |= LVS_ICON;
250 }
251
252 if ( style & wxLC_SMALL_ICON )
253 {
254 if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON )
255 oldStyle -= LVS_ICON;
256 if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT )
257 oldStyle -= LVS_REPORT;
258 if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST )
259 oldStyle -= LVS_LIST;
260 wstyle |= LVS_SMALLICON;
261 }
262
263 if ( style & wxLC_LIST )
264 {
265 if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON )
266 oldStyle -= LVS_ICON;
267 if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT )
268 oldStyle -= LVS_REPORT;
269 if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON )
270 oldStyle -= LVS_SMALLICON;
271 wstyle |= LVS_LIST;
272 }
273
274 if ( style & wxLC_REPORT )
275 {
276 if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON )
277 oldStyle -= LVS_ICON;
278 if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST )
279 oldStyle -= LVS_LIST;
280 if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON )
281 oldStyle -= LVS_SMALLICON;
282 wstyle |= LVS_REPORT;
283 }
284
285 if ( style & wxLC_ALIGN_LEFT )
286 {
287 if ( oldStyle & LVS_ALIGNTOP )
288 oldStyle -= LVS_ALIGNTOP;
289 wstyle |= LVS_ALIGNLEFT;
290 }
291
292 if ( style & wxLC_ALIGN_TOP )
293 {
294 if ( oldStyle & LVS_ALIGNLEFT )
295 oldStyle -= LVS_ALIGNLEFT;
296 wstyle |= LVS_ALIGNTOP;
297 }
298
299 if ( style & wxLC_AUTOARRANGE )
300 wstyle |= LVS_AUTOARRANGE;
301
302 // Apparently, no such style (documentation wrong?)
303 /*
304 if ( style & wxLC_BUTTON )
305 wstyle |= LVS_BUTTON;
306 */
307
308 if ( style & wxLC_NO_SORT_HEADER )
309 wstyle |= LVS_NOSORTHEADER;
310
311 if ( style & wxLC_NO_HEADER )
312 wstyle |= LVS_NOCOLUMNHEADER;
313
314 if ( style & wxLC_EDIT_LABELS )
315 wstyle |= LVS_EDITLABELS;
316
317 if ( style & wxLC_SINGLE_SEL )
318 wstyle |= LVS_SINGLESEL;
319
320 if ( style & wxLC_SORT_ASCENDING )
321 {
322 if ( oldStyle & LVS_SORTDESCENDING )
323 oldStyle -= LVS_SORTDESCENDING;
324 wstyle |= LVS_SORTASCENDING;
325 }
326
327 if ( style & wxLC_SORT_DESCENDING )
328 {
329 if ( oldStyle & LVS_SORTASCENDING )
330 oldStyle -= LVS_SORTASCENDING;
331 wstyle |= LVS_SORTDESCENDING;
332 }
333
334 return wstyle;
335 }
336
337 // Sets the background colour (GetBackgroundColour already implicit in
338 // wxWindow class)
339 void wxListCtrl::SetBackgroundColour(const wxColour& col)
340 {
341 wxWindow::SetBackgroundColour(col);
342
343 ListView_SetBkColor((HWND) GetHWND(), PALETTERGB(col.Red(), col.Green(), col.Blue()));
344 }
345
346 // Gets information about this column
347 bool wxListCtrl::GetColumn(int col, wxListItem& item) const
348 {
349 LV_COLUMN lvCol;
350 lvCol.mask = 0;
351 lvCol.fmt = 0;
352 lvCol.pszText = NULL;
353
354 if ( item.m_mask & wxLIST_MASK_TEXT )
355 {
356 lvCol.mask |= LVCF_TEXT;
357 lvCol.pszText = new char[513];
358 lvCol.cchTextMax = 512;
359 }
360
361 bool success = (ListView_GetColumn((HWND) GetHWND(), col, & lvCol) != 0);
362
363 // item.m_subItem = lvCol.iSubItem;
364 item.m_width = lvCol.cx;
365
366 if ( (item.m_mask & wxLIST_MASK_TEXT) && lvCol.pszText )
367 {
368 item.m_text = lvCol.pszText;
369 delete[] lvCol.pszText;
370 }
371
372 if ( item.m_mask & wxLIST_MASK_FORMAT )
373 {
374 if (lvCol.fmt == LVCFMT_LEFT)
375 item.m_format = wxLIST_FORMAT_LEFT;
376 else if (lvCol.fmt == LVCFMT_RIGHT)
377 item.m_format = wxLIST_FORMAT_RIGHT;
378 else if (lvCol.fmt == LVCFMT_CENTER)
379 item.m_format = wxLIST_FORMAT_CENTRE;
380 }
381
382 return success;
383 }
384
385 // Sets information about this column
386 bool wxListCtrl::SetColumn(int col, wxListItem& item)
387 {
388 LV_COLUMN lvCol;
389 lvCol.mask = 0;
390 lvCol.fmt = 0;
391 lvCol.pszText = NULL;
392
393 if ( item.m_mask & wxLIST_MASK_TEXT )
394 {
395 lvCol.mask |= LVCF_TEXT;
396 lvCol.pszText = WXSTRINGCAST item.m_text;
397 lvCol.cchTextMax = 0; // Ignored
398 }
399 if ( item.m_mask & wxLIST_MASK_FORMAT )
400 {
401 lvCol.mask |= LVCF_FMT;
402
403 if ( item.m_format == wxLIST_FORMAT_LEFT )
404 lvCol.fmt = LVCFMT_LEFT;
405 if ( item.m_format == wxLIST_FORMAT_RIGHT )
406 lvCol.fmt = LVCFMT_RIGHT;
407 if ( item.m_format == wxLIST_FORMAT_CENTRE )
408 lvCol.fmt = LVCFMT_CENTER;
409 }
410
411 if ( item.m_mask & wxLIST_MASK_WIDTH )
412 {
413 lvCol.mask |= LVCF_WIDTH;
414 lvCol.cx = item.m_width;
415
416 if ( lvCol.cx == wxLIST_AUTOSIZE)
417 lvCol.cx = LVSCW_AUTOSIZE;
418 else if ( lvCol.cx == wxLIST_AUTOSIZE_USEHEADER)
419 lvCol.cx = LVSCW_AUTOSIZE_USEHEADER;
420 }
421 lvCol.mask |= LVCF_SUBITEM;
422 lvCol.iSubItem = col;
423 return (ListView_SetColumn((HWND) GetHWND(), col, & lvCol) != 0);
424 }
425
426 // Gets the column width
427 int wxListCtrl::GetColumnWidth(int col) const
428 {
429 return ListView_GetColumnWidth((HWND) GetHWND(), col);
430 }
431
432 // Sets the column width
433 bool wxListCtrl::SetColumnWidth(int col, int width)
434 {
435 int col2 = col;
436 if ( m_windowStyle & wxLC_LIST )
437 col2 = -1;
438
439 int width2 = width;
440 if ( width2 == wxLIST_AUTOSIZE)
441 width2 = LVSCW_AUTOSIZE;
442 else if ( width2 == wxLIST_AUTOSIZE_USEHEADER)
443 width2 = LVSCW_AUTOSIZE_USEHEADER;
444
445 return (ListView_SetColumnWidth((HWND) GetHWND(), col2, width2) != 0);
446 }
447
448 // Gets the number of items that can fit vertically in the
449 // visible area of the list control (list or report view)
450 // or the total number of items in the list control (icon
451 // or small icon view)
452 int wxListCtrl::GetCountPerPage(void) const
453 {
454 return ListView_GetCountPerPage((HWND) GetHWND());
455 }
456
457 // Gets the edit control for editing labels.
458 wxTextCtrl* wxListCtrl::GetEditControl(void) const
459 {
460 return m_textCtrl;
461 }
462
463 // Gets information about the item
464 bool wxListCtrl::GetItem(wxListItem& info) const
465 {
466 LV_ITEM lvItem;
467 lvItem.pszText = NULL;
468 if ( info.m_mask & wxLIST_MASK_TEXT )
469 {
470 lvItem.pszText = new char[513];
471 lvItem.cchTextMax = 512;
472 }
473 bool success = (::SendMessage((HWND) GetHWND(), LVM_GETITEM, 0, (LPARAM)& lvItem) != 0);
474
475 if ( !success )
476 {
477 if (lvItem.pszText)
478 delete[] lvItem.pszText;
479
480 return FALSE;
481 }
482
483 wxConvertFromMSWListItem(this, info, lvItem);
484
485 if (lvItem.pszText)
486 delete[] lvItem.pszText;
487
488 return success;
489 }
490
491 // Sets information about the item
492 bool wxListCtrl::SetItem(wxListItem& info)
493 {
494 LV_ITEM item;
495 wxConvertToMSWListItem(this, info, item);
496 item.cchTextMax = 0;
497 return (ListView_SetItem((HWND) GetHWND(), &item) != 0);
498 }
499
500 long wxListCtrl::SetItem(long index, int col, const wxString& label, int imageId)
501 {
502 wxListItem info;
503 info.m_text = label;
504 info.m_mask = wxLIST_MASK_TEXT;
505 info.m_itemId = index;
506 info.m_col = col;
507 if ( imageId > -1 )
508 {
509 info.m_image = imageId;
510 info.m_mask |= wxLIST_MASK_IMAGE;
511 }
512 return SetItem(info);
513 }
514
515
516 // Gets the item state
517 int wxListCtrl::GetItemState(long item, long stateMask) const
518 {
519 wxListItem info;
520
521 info.m_mask = wxLIST_MASK_STATE ;
522 info.m_stateMask = stateMask;
523 info.m_itemId = item;
524
525 if (!GetItem(info))
526 return 0;
527
528 return info.m_state;
529 }
530
531 // Sets the item state
532 bool wxListCtrl::SetItemState(long item, long state, long stateMask)
533 {
534 wxListItem info;
535
536 info.m_mask = wxLIST_MASK_STATE ;
537 info.m_state = state;
538 info.m_stateMask = stateMask;
539 info.m_itemId = item;
540
541 return SetItem(info);
542 }
543
544 // Sets the item image
545 bool wxListCtrl::SetItemImage(long item, int image, int selImage)
546 {
547 wxListItem info;
548
549 info.m_mask = wxLIST_MASK_IMAGE ;
550 info.m_image = image;
551 info.m_itemId = item;
552
553 return SetItem(info);
554 }
555
556 // Gets the item text
557 wxString wxListCtrl::GetItemText(long item) const
558 {
559 wxListItem info;
560
561 info.m_mask = wxLIST_MASK_TEXT ;
562 info.m_itemId = item;
563
564 if (!GetItem(info))
565 return wxString("");
566 return info.m_text;
567 }
568
569 // Sets the item text
570 void wxListCtrl::SetItemText(long item, const wxString& str)
571 {
572 wxListItem info;
573
574 info.m_mask = wxLIST_MASK_TEXT ;
575 info.m_itemId = item;
576 info.m_text = str;
577
578 SetItem(info);
579 }
580
581 // Gets the item data
582 long wxListCtrl::GetItemData(long item) const
583 {
584 wxListItem info;
585
586 info.m_mask = wxLIST_MASK_DATA ;
587 info.m_itemId = item;
588
589 if (!GetItem(info))
590 return 0;
591 return info.m_data;
592 }
593
594 // Sets the item data
595 bool wxListCtrl::SetItemData(long item, long data)
596 {
597 wxListItem info;
598
599 info.m_mask = wxLIST_MASK_DATA ;
600 info.m_itemId = item;
601 info.m_data = data;
602
603 return SetItem(info);
604 }
605
606 // Gets the item rectangle
607 bool wxListCtrl::GetItemRect(long item, wxRectangle& rect, int code) const
608 {
609 RECT rect2;
610
611 int code2 = LVIR_BOUNDS;
612 if ( code == wxLIST_RECT_BOUNDS )
613 code2 = LVIR_BOUNDS;
614 else if ( code == wxLIST_RECT_ICON )
615 code2 = LVIR_ICON;
616 else if ( code == wxLIST_RECT_LABEL )
617 code2 = LVIR_LABEL;
618
619 bool success = (ListView_GetItemRect((HWND) GetHWND(), (int) item, &rect2, code2) != 0);
620
621 rect.x = rect2.left;
622 rect.y = rect2.top;
623 rect.width = rect2.right - rect2.left;
624 rect.height = rect2.bottom - rect2.left;
625 return success;
626 }
627
628 // Gets the item position
629 bool wxListCtrl::GetItemPosition(long item, wxPoint& pos) const
630 {
631 POINT pt;
632
633 bool success = (ListView_GetItemPosition((HWND) GetHWND(), (int) item, &pt) != 0);
634
635 pos.x = pt.x; pos.y = pt.y;
636 return success;
637 }
638
639 // Sets the item position.
640 bool wxListCtrl::SetItemPosition(long item, const wxPoint& pos)
641 {
642 return (ListView_SetItemPosition((HWND) GetHWND(), (int) item, pos.x, pos.y) != 0);
643 }
644
645 // Gets the number of items in the list control
646 int wxListCtrl::GetItemCount(void) const
647 {
648 return ListView_GetItemCount((HWND) GetHWND());
649 }
650
651 // Retrieves the spacing between icons in pixels.
652 // If small is TRUE, gets the spacing for the small icon
653 // view, otherwise the large icon view.
654 int wxListCtrl::GetItemSpacing(bool isSmall) const
655 {
656 return ListView_GetItemSpacing((HWND) GetHWND(), (BOOL) isSmall);
657 }
658
659 // Gets the number of selected items in the list control
660 int wxListCtrl::GetSelectedItemCount(void) const
661 {
662 return ListView_GetSelectedCount((HWND) GetHWND());
663 }
664
665 // Gets the text colour of the listview
666 wxColour wxListCtrl::GetTextColour(void) const
667 {
668 COLORREF ref = ListView_GetTextColor((HWND) GetHWND());
669 wxColour col(GetRValue(ref), GetGValue(ref), GetBValue(ref));
670 return col;
671 }
672
673 // Sets the text colour of the listview
674 void wxListCtrl::SetTextColour(const wxColour& col)
675 {
676 ListView_SetTextColor((HWND) GetHWND(), PALETTERGB(col.Red(), col.Blue(), col.Green()));
677 }
678
679 // Gets the index of the topmost visible item when in
680 // list or report view
681 long wxListCtrl::GetTopItem(void) const
682 {
683 return (long) ListView_GetTopIndex((HWND) GetHWND());
684 }
685
686 // Searches for an item, starting from 'item'.
687 // 'geometry' is one of
688 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
689 // 'state' is a state bit flag, one or more of
690 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
691 // item can be -1 to find the first item that matches the
692 // specified flags.
693 // Returns the item or -1 if unsuccessful.
694 long wxListCtrl::GetNextItem(long item, int geom, int state) const
695 {
696 long flags = 0;
697
698 if ( geom == wxLIST_NEXT_ABOVE )
699 flags |= LVNI_ABOVE;
700 if ( geom == wxLIST_NEXT_ALL )
701 flags |= LVNI_ALL;
702 if ( geom == wxLIST_NEXT_BELOW )
703 flags |= LVNI_BELOW;
704 if ( geom == wxLIST_NEXT_LEFT )
705 flags |= LVNI_TOLEFT;
706 if ( geom == wxLIST_NEXT_RIGHT )
707 flags |= LVNI_TORIGHT;
708
709 if ( state & wxLIST_STATE_CUT )
710 flags |= LVNI_CUT;
711 if ( state & wxLIST_STATE_DROPHILITED )
712 flags |= LVNI_DROPHILITED;
713 if ( state & wxLIST_STATE_FOCUSED )
714 flags |= LVNI_FOCUSED;
715 if ( state & wxLIST_STATE_SELECTED )
716 flags |= LVNI_SELECTED;
717
718 return (long) ListView_GetNextItem((HWND) GetHWND(), item, flags);
719 }
720
721
722 wxImageList *wxListCtrl::GetImageList(int which) const
723 {
724 if ( which == wxIMAGE_LIST_NORMAL )
725 {
726 return m_imageListNormal;
727 }
728 else if ( which == wxIMAGE_LIST_SMALL )
729 {
730 return m_imageListSmall;
731 }
732 else if ( which == wxIMAGE_LIST_STATE )
733 {
734 return m_imageListState;
735 }
736 return NULL;
737 }
738
739 void wxListCtrl::SetImageList(wxImageList *imageList, int which)
740 {
741 int flags = 0;
742 if ( which == wxIMAGE_LIST_NORMAL )
743 {
744 flags = LVSIL_NORMAL;
745 m_imageListNormal = imageList;
746 }
747 else if ( which == wxIMAGE_LIST_SMALL )
748 {
749 flags = LVSIL_SMALL;
750 m_imageListSmall = imageList;
751 }
752 else if ( which == wxIMAGE_LIST_STATE )
753 {
754 flags = LVSIL_STATE;
755 m_imageListState = imageList;
756 }
757 ListView_SetImageList((HWND) GetHWND(), (HIMAGELIST) imageList ? imageList->GetHIMAGELIST() : 0, flags);
758 }
759
760 // Operations
761 ////////////////////////////////////////////////////////////////////////////
762
763 // Arranges the items
764 bool wxListCtrl::Arrange(int flag)
765 {
766 UINT code = 0;
767 if ( flag == wxLIST_ALIGN_LEFT )
768 code = LVA_ALIGNLEFT;
769 else if ( flag == wxLIST_ALIGN_TOP )
770 code = LVA_ALIGNTOP;
771 else if ( flag == wxLIST_ALIGN_DEFAULT )
772 code = LVA_DEFAULT;
773 else if ( flag == wxLIST_ALIGN_SNAP_TO_GRID )
774 code = LVA_SNAPTOGRID;
775
776 return (ListView_Arrange((HWND) GetHWND(), code) != 0);
777 }
778
779 // Deletes an item
780 bool wxListCtrl::DeleteItem(long item)
781 {
782 return (ListView_DeleteItem((HWND) GetHWND(), (int) item) != 0);
783 }
784
785 // Deletes all items
786 bool wxListCtrl::DeleteAllItems(void)
787 {
788 return (ListView_DeleteAllItems((HWND) GetHWND()) != 0);
789 }
790
791 // Deletes all items
792 bool wxListCtrl::DeleteAllColumns(void)
793 {
794 int i;
795 for ( i = 0; i < m_colCount; i++)
796 {
797 if (ListView_DeleteColumn((HWND) GetHWND(), 0) != 0)
798 m_colCount --;
799 }
800 return (m_colCount == 0);
801 }
802
803 // Deletes a column
804 bool wxListCtrl::DeleteColumn(int col)
805 {
806 bool success = (ListView_DeleteColumn((HWND) GetHWND(), col) != 0);
807
808 if ( success && (m_colCount > 0) )
809 m_colCount --;
810 return success;
811 }
812
813 // Clears items, and columns if there are any.
814 void wxListCtrl::ClearAll(void)
815 {
816 DeleteAllItems();
817 if ( m_colCount > 0 )
818 DeleteAllColumns();
819 }
820
821 wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass)
822 {
823 wxASSERT( (textControlClass->IsKindOf(CLASSINFO(wxTextCtrl))) );
824
825 HWND hWnd = (HWND) ListView_EditLabel((HWND) GetHWND(), item);
826
827 if (m_textCtrl)
828 {
829 m_textCtrl->UnsubclassWin();
830 m_textCtrl->SetHWND(0);
831 delete m_textCtrl;
832 m_textCtrl = NULL;
833 }
834
835 m_textCtrl = (wxTextCtrl*) textControlClass->CreateObject();
836 m_textCtrl->SetHWND((WXHWND) hWnd);
837 m_textCtrl->SubclassWin((WXHWND) hWnd);
838
839 return m_textCtrl;
840 }
841
842 // End label editing, optionally cancelling the edit
843 bool wxListCtrl::EndEditLabel(bool cancel)
844 {
845 wxASSERT( FALSE);
846
847 /* I don't know how to implement this: there's no such macro as ListView_EndEditLabelNow.
848 * ???
849 bool success = (ListView_EndEditLabelNow((HWND) GetHWND(), cancel) != 0);
850
851 if (m_textCtrl)
852 {
853 m_textCtrl->UnsubclassWin();
854 m_textCtrl->SetHWND(0);
855 delete m_textCtrl;
856 m_textCtrl = NULL;
857 }
858 return success;
859 */
860 return FALSE;
861 }
862
863
864 // Ensures this item is visible
865 bool wxListCtrl::EnsureVisible(long item)
866 {
867 return (ListView_EnsureVisible((HWND) GetHWND(), (int) item, FALSE) != 0);
868 }
869
870 // Find an item whose label matches this string, starting from the item after 'start'
871 // or the beginning if 'start' is -1.
872 long wxListCtrl::FindItem(long start, const wxString& str, bool partial)
873 {
874 LV_FINDINFO findInfo;
875
876 findInfo.flags = LVFI_STRING;
877 if ( partial )
878 findInfo.flags |= LVFI_STRING;
879 findInfo.psz = WXSTRINGCAST str;
880
881 return ListView_FindItem((HWND) GetHWND(), (int) start, & findInfo);
882 }
883
884 // Find an item whose data matches this data, starting from the item after 'start'
885 // or the beginning if 'start' is -1.
886 long wxListCtrl::FindItem(long start, long data)
887 {
888 LV_FINDINFO findInfo;
889
890 findInfo.flags = LVFI_PARAM;
891 findInfo.lParam = data;
892
893 return ListView_FindItem((HWND) GetHWND(), (int) start, & findInfo);
894 }
895
896 // Find an item nearest this position in the specified direction, starting from
897 // the item after 'start' or the beginning if 'start' is -1.
898 long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction)
899 {
900 LV_FINDINFO findInfo;
901
902 findInfo.flags = LVFI_NEARESTXY;
903 findInfo.pt.x = pt.x;
904 findInfo.pt.y = pt.y;
905 findInfo.vkDirection = VK_RIGHT;
906
907 if ( direction == wxLIST_FIND_UP )
908 findInfo.vkDirection = VK_UP;
909 else if ( direction == wxLIST_FIND_DOWN )
910 findInfo.vkDirection = VK_DOWN;
911 else if ( direction == wxLIST_FIND_LEFT )
912 findInfo.vkDirection = VK_LEFT;
913 else if ( direction == wxLIST_FIND_RIGHT )
914 findInfo.vkDirection = VK_RIGHT;
915
916 return ListView_FindItem((HWND) GetHWND(), (int) start, & findInfo);
917 }
918
919 // Determines which item (if any) is at the specified point,
920 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
921 long wxListCtrl::HitTest(const wxPoint& point, int& flags)
922 {
923 LV_HITTESTINFO hitTestInfo;
924 hitTestInfo.pt.x = (int) point.x;
925 hitTestInfo.pt.y = (int) point.y;
926
927 ListView_HitTest((HWND) GetHWND(), & hitTestInfo);
928
929 flags = 0;
930 if ( hitTestInfo.flags & LVHT_ABOVE )
931 flags |= wxLIST_HITTEST_ABOVE;
932 if ( hitTestInfo.flags & LVHT_BELOW )
933 flags |= wxLIST_HITTEST_BELOW;
934 if ( hitTestInfo.flags & LVHT_NOWHERE )
935 flags |= wxLIST_HITTEST_NOWHERE;
936 if ( hitTestInfo.flags & LVHT_ONITEMICON )
937 flags |= wxLIST_HITTEST_ONITEMICON;
938 if ( hitTestInfo.flags & LVHT_ONITEMLABEL )
939 flags |= wxLIST_HITTEST_ONITEMLABEL;
940 if ( hitTestInfo.flags & LVHT_ONITEMSTATEICON )
941 flags |= wxLIST_HITTEST_ONITEMSTATEICON;
942 if ( hitTestInfo.flags & LVHT_TOLEFT )
943 flags |= wxLIST_HITTEST_TOLEFT;
944 if ( hitTestInfo.flags & LVHT_TORIGHT )
945 flags |= wxLIST_HITTEST_TORIGHT;
946
947 return (long) hitTestInfo.iItem ;
948 }
949
950 // Inserts an item, returning the index of the new item if successful,
951 // -1 otherwise.
952 long wxListCtrl::InsertItem(wxListItem& info)
953 {
954 LV_ITEM item;
955 wxConvertToMSWListItem(this, info, item);
956
957 return (long) ListView_InsertItem((HWND) GetHWND(), & item);
958 }
959
960 long wxListCtrl::InsertItem(long index, const wxString& label)
961 {
962 wxListItem info;
963 info.m_text = label;
964 info.m_mask = wxLIST_MASK_TEXT;
965 info.m_itemId = index;
966 return InsertItem(info);
967 }
968
969 // Inserts an image item
970 long wxListCtrl::InsertItem(long index, int imageIndex)
971 {
972 wxListItem info;
973 info.m_image = imageIndex;
974 info.m_mask = wxLIST_MASK_IMAGE;
975 info.m_itemId = index;
976 return InsertItem(info);
977 }
978
979 // Inserts an image/string item
980 long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex)
981 {
982 wxListItem info;
983 info.m_image = imageIndex;
984 info.m_text = label;
985 info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT;
986 info.m_itemId = index;
987 return InsertItem(info);
988 }
989
990 // For list view mode (only), inserts a column.
991 long wxListCtrl::InsertColumn(long col, wxListItem& item)
992 {
993 LV_COLUMN lvCol;
994 lvCol.mask = 0;
995 lvCol.fmt = 0;
996 lvCol.pszText = NULL;
997
998 if ( item.m_mask & wxLIST_MASK_TEXT )
999 {
1000 lvCol.mask |= LVCF_TEXT;
1001 lvCol.pszText = WXSTRINGCAST item.m_text;
1002 lvCol.cchTextMax = 0; // Ignored
1003 }
1004 if ( item.m_mask & wxLIST_MASK_FORMAT )
1005 {
1006 lvCol.mask |= LVCF_FMT;
1007
1008 if ( item.m_format == wxLIST_FORMAT_LEFT )
1009 lvCol.fmt = LVCFMT_LEFT;
1010 if ( item.m_format == wxLIST_FORMAT_RIGHT )
1011 lvCol.fmt = LVCFMT_RIGHT;
1012 if ( item.m_format == wxLIST_FORMAT_CENTRE )
1013 lvCol.fmt = LVCFMT_CENTER;
1014 }
1015
1016 if ( item.m_mask & wxLIST_MASK_WIDTH )
1017 {
1018 lvCol.mask |= LVCF_WIDTH;
1019 lvCol.cx = item.m_width;
1020
1021 if ( lvCol.cx == wxLIST_AUTOSIZE)
1022 lvCol.cx = LVSCW_AUTOSIZE;
1023 else if ( lvCol.cx == wxLIST_AUTOSIZE_USEHEADER)
1024 lvCol.cx = LVSCW_AUTOSIZE_USEHEADER;
1025 }
1026 lvCol.mask |= LVCF_SUBITEM;
1027 lvCol.iSubItem = col;
1028
1029 bool success = (ListView_InsertColumn((HWND) GetHWND(), col, & lvCol) != 0);
1030 if ( success )
1031 m_colCount ++;
1032 return success;
1033 }
1034
1035 long wxListCtrl::InsertColumn(long col, const wxString& heading, int format,
1036 int width)
1037 {
1038 wxListItem item;
1039 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
1040 item.m_text = heading;
1041 if ( width > -1 )
1042 {
1043 item.m_mask |= wxLIST_MASK_WIDTH;
1044 item.m_width = width;
1045 }
1046 item.m_format = format;
1047
1048 return InsertColumn(col, item);
1049 }
1050
1051 // Scrolls the list control. If in icon, small icon or report view mode,
1052 // x specifies the number of pixels to scroll. If in list view mode, x
1053 // specifies the number of columns to scroll.
1054 // If in icon, small icon or list view mode, y specifies the number of pixels
1055 // to scroll. If in report view mode, y specifies the number of lines to scroll.
1056 bool wxListCtrl::ScrollList(int dx, int dy)
1057 {
1058 return (ListView_Scroll((HWND) GetHWND(), dx, dy) != 0);
1059 }
1060
1061 // Sort items.
1062
1063 // fn is a function which takes 3 long arguments: item1, item2, data.
1064 // item1 is the long data associated with a first item (NOT the index).
1065 // item2 is the long data associated with a second item (NOT the index).
1066 // data is the same value as passed to SortItems.
1067 // The return value is a negative number if the first item should precede the second
1068 // item, a positive number of the second item should precede the first,
1069 // or zero if the two items are equivalent.
1070
1071 // data is arbitrary data to be passed to the sort function.
1072 bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data)
1073 {
1074 return (ListView_SortItems((HWND) GetHWND(), (PFNLVCOMPARE) fn, data) != 0);
1075 }
1076
1077 bool wxListCtrl::MSWCommand(WXUINT cmd, WXWORD id)
1078 {
1079 if (cmd == EN_UPDATE)
1080 {
1081 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, id);
1082 event.SetEventObject( this );
1083 ProcessCommand(event);
1084 return TRUE;
1085 }
1086 else if (cmd == EN_KILLFOCUS)
1087 {
1088 wxCommandEvent event(wxEVT_KILL_FOCUS, id);
1089 event.SetEventObject( this );
1090 ProcessCommand(event);
1091 return TRUE;
1092 }
1093 else return FALSE;
1094 }
1095
1096 bool wxListCtrl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam)
1097 {
1098 wxListEvent event(wxEVT_NULL, m_windowId);
1099 wxEventType eventType = wxEVT_NULL;
1100 NMHDR *hdr1 = (NMHDR *) lParam;
1101 switch ( hdr1->code )
1102 {
1103 case LVN_BEGINDRAG:
1104 {
1105 eventType = wxEVT_COMMAND_LIST_BEGIN_DRAG;
1106 NM_LISTVIEW *hdr = (NM_LISTVIEW *)lParam;
1107 event.m_itemIndex = hdr->iItem;
1108 event.m_pointDrag.x = hdr->ptAction.x;
1109 event.m_pointDrag.y = hdr->ptAction.y;
1110 break;
1111 }
1112 case LVN_BEGINLABELEDIT:
1113 {
1114 eventType = wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT;
1115 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1116 wxConvertFromMSWListItem(this, event.m_item, info->item, (HWND) GetHWND());
1117 break;
1118 }
1119 case LVN_BEGINRDRAG:
1120 {
1121 eventType = wxEVT_COMMAND_LIST_BEGIN_RDRAG;
1122 NM_LISTVIEW* hdr = (NM_LISTVIEW*)lParam;
1123 event.m_itemIndex = hdr->iItem;
1124 event.m_pointDrag.x = hdr->ptAction.x;
1125 event.m_pointDrag.y = hdr->ptAction.y;
1126 break;
1127 }
1128 case LVN_COLUMNCLICK:
1129 {
1130 eventType = wxEVT_COMMAND_LIST_COL_CLICK;
1131 NM_LISTVIEW* hdr = (NM_LISTVIEW*)lParam;
1132 event.m_itemIndex = -1;
1133 event.m_col = hdr->iSubItem;
1134 break;
1135 }
1136 case LVN_DELETEALLITEMS:
1137 {
1138 eventType = wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS;
1139 // NM_LISTVIEW* hdr = (NM_LISTVIEW*)lParam;
1140 event.m_itemIndex = -1;
1141 break;
1142 }
1143 case LVN_DELETEITEM:
1144 {
1145 eventType = wxEVT_COMMAND_LIST_DELETE_ITEM;
1146 NM_LISTVIEW* hdr = (NM_LISTVIEW*)lParam;
1147 event.m_itemIndex = hdr->iItem;
1148 break;
1149 }
1150 case LVN_ENDLABELEDIT:
1151 {
1152 eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT;
1153 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1154 wxConvertFromMSWListItem(this, event.m_item, info->item, (HWND) GetHWND());
1155 if ( info->item.pszText == NULL || info->item.iItem == -1 )
1156 event.m_cancelled = TRUE;
1157 break;
1158 }
1159 case LVN_GETDISPINFO:
1160 {
1161 // return FALSE;
1162 // TODO: some text buffering here, I think
1163 // TODO: API for getting Windows to retrieve values
1164 // on demand.
1165 eventType = wxEVT_COMMAND_LIST_GET_INFO;
1166 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1167 wxConvertFromMSWListItem(this, event.m_item, info->item, (HWND) GetHWND());
1168 break;
1169 }
1170 case LVN_INSERTITEM:
1171 {
1172 eventType = wxEVT_COMMAND_LIST_INSERT_ITEM;
1173 NM_LISTVIEW* hdr = (NM_LISTVIEW*)lParam;
1174 event.m_itemIndex = hdr->iItem;
1175 break;
1176 }
1177 case LVN_ITEMCHANGED:
1178 {
1179 // This needs to be sent to wxListCtrl as a rather more
1180 // concrete event. For now, just detect a selection
1181 // or deselection.
1182 NM_LISTVIEW* hdr = (NM_LISTVIEW*)lParam;
1183 if ( (hdr->uNewState & LVIS_SELECTED) && !(hdr->uOldState & LVIS_SELECTED) )
1184 {
1185 eventType = wxEVT_COMMAND_LIST_ITEM_SELECTED;
1186 event.m_itemIndex = hdr->iItem;
1187 }
1188 else if ( !(hdr->uNewState & LVIS_SELECTED) && (hdr->uOldState & LVIS_SELECTED) )
1189 {
1190 eventType = wxEVT_COMMAND_LIST_ITEM_DESELECTED;
1191 event.m_itemIndex = hdr->iItem;
1192 }
1193 else
1194 return FALSE;
1195 break;
1196 }
1197 case LVN_KEYDOWN:
1198 {
1199 eventType = wxEVT_COMMAND_LIST_KEY_DOWN;
1200 LV_KEYDOWN *info = (LV_KEYDOWN *)lParam;
1201 event.m_code = wxCharCodeMSWToWX(info->wVKey);
1202 break;
1203 }
1204 case LVN_SETDISPINFO:
1205 {
1206 eventType = wxEVT_COMMAND_LIST_SET_INFO;
1207 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1208 wxConvertFromMSWListItem(this, event.m_item, info->item, (HWND) GetHWND());
1209 break;
1210 }
1211
1212 default :
1213 return wxControl::MSWNotify(wParam, lParam);
1214 break;
1215 }
1216
1217 event.SetEventObject( this );
1218 event.SetEventType(eventType);
1219
1220 if ( !GetEventHandler()->ProcessEvent(event) )
1221 return FALSE;
1222
1223 if (hdr1->code == LVN_GETDISPINFO)
1224 {
1225 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1226 if ( info->item.mask & LVIF_TEXT )
1227 {
1228 if ( !event.m_item.m_text.IsNull() )
1229 {
1230 info->item.pszText = AddPool(event.m_item.m_text);
1231 info->item.cchTextMax = strlen(info->item.pszText) + 1;
1232 }
1233 }
1234 // wxConvertToMSWListItem(this, event.m_item, info->item);
1235 }
1236
1237 return TRUE;
1238 }
1239
1240 char *wxListCtrl::AddPool(const wxString& str)
1241 {
1242 // Remove the first element if 3 strings exist
1243 if ( m_stringPool.Number() == 3 )
1244 {
1245 wxNode *node = m_stringPool.First();
1246 delete[] (char *)node->Data();
1247 delete node;
1248 }
1249 wxNode *node = m_stringPool.Add((char *) (const char *)str);
1250 return (char *)node->Data();
1251 }
1252
1253 // List item structure
1254 wxListItem::wxListItem(void)
1255 {
1256 m_mask = 0;
1257 m_itemId = 0;
1258 m_col = 0;
1259 m_state = 0;
1260 m_stateMask = 0;
1261 m_image = 0;
1262 m_data = 0;
1263
1264 m_format = wxLIST_FORMAT_CENTRE;
1265 m_width = 0;
1266 }
1267
1268 static void wxConvertFromMSWListItem(const wxListCtrl *ctrl, wxListItem& info, LV_ITEM& lvItem, HWND getFullInfo)
1269 {
1270 info.m_data = lvItem.lParam;
1271 info.m_mask = 0;
1272 info.m_state = 0;
1273 info.m_stateMask = 0;
1274 info.m_itemId = lvItem.iItem;
1275
1276 long oldMask = lvItem.mask;
1277
1278 bool needText = FALSE;
1279 if (getFullInfo != 0)
1280 {
1281 if ( lvItem.mask & LVIF_TEXT )
1282 needText = FALSE;
1283 else
1284 needText = TRUE;
1285
1286 if ( needText )
1287 {
1288 lvItem.pszText = new char[513];
1289 lvItem.cchTextMax = 512;
1290 }
1291 // lvItem.mask |= TVIF_HANDLE | TVIF_STATE | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM ;
1292 lvItem.mask |= LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM ;
1293 ::SendMessage(getFullInfo, LVM_GETITEM, 0, (LPARAM)& lvItem) ;
1294 }
1295
1296 if ( lvItem.mask & LVIF_STATE )
1297 {
1298 info.m_mask |= wxLIST_MASK_STATE;
1299
1300 if ( lvItem.stateMask & LVIS_CUT)
1301 {
1302 info.m_stateMask |= wxLIST_STATE_CUT ;
1303 if ( lvItem.state & LVIS_CUT )
1304 info.m_state |= wxLIST_STATE_CUT ;
1305 }
1306 if ( lvItem.stateMask & LVIS_DROPHILITED)
1307 {
1308 info.m_stateMask |= wxLIST_STATE_DROPHILITED ;
1309 if ( lvItem.state & LVIS_DROPHILITED )
1310 info.m_state |= wxLIST_STATE_DROPHILITED ;
1311 }
1312 if ( lvItem.stateMask & LVIS_FOCUSED)
1313 {
1314 info.m_stateMask |= wxLIST_STATE_FOCUSED ;
1315 if ( lvItem.state & LVIS_FOCUSED )
1316 info.m_state |= wxLIST_STATE_FOCUSED ;
1317 }
1318 if ( lvItem.stateMask & LVIS_SELECTED)
1319 {
1320 info.m_stateMask |= wxLIST_STATE_SELECTED ;
1321 if ( lvItem.state & LVIS_SELECTED )
1322 info.m_state |= wxLIST_STATE_SELECTED ;
1323 }
1324 }
1325
1326 if ( lvItem.mask & LVIF_TEXT )
1327 {
1328 info.m_mask |= wxLIST_MASK_TEXT;
1329 info.m_text = lvItem.pszText;
1330 }
1331 if ( lvItem.mask & LVIF_IMAGE )
1332 {
1333 info.m_mask |= wxLIST_MASK_IMAGE;
1334 info.m_image = lvItem.iImage;
1335 }
1336 if ( lvItem.mask & LVIF_PARAM )
1337 info.m_mask |= wxLIST_MASK_DATA;
1338 if ( lvItem.mask & LVIF_DI_SETITEM )
1339 info.m_mask |= wxLIST_SET_ITEM;
1340 info.m_col = lvItem.iSubItem;
1341
1342 if (needText)
1343 {
1344 if (lvItem.pszText)
1345 delete[] lvItem.pszText;
1346 }
1347 lvItem.mask = oldMask ;
1348 }
1349
1350 static void wxConvertToMSWListItem(const wxListCtrl *ctrl, wxListItem& info, LV_ITEM& lvItem)
1351 {
1352 lvItem.iItem = (int) info.m_itemId ;
1353
1354 lvItem.iImage = info.m_image ;
1355 lvItem.lParam = info.m_data;
1356 lvItem.stateMask = 0;
1357 lvItem.state = 0;
1358 lvItem.mask = 0;
1359 lvItem.iSubItem = info.m_col;
1360
1361 if (info.m_mask & wxLIST_MASK_STATE)
1362 {
1363 lvItem.mask |= LVIF_STATE ;
1364 if (info.m_stateMask & wxLIST_STATE_CUT)
1365 {
1366 lvItem.stateMask |= LVIS_CUT ;
1367 if (info.m_state & wxLIST_STATE_CUT)
1368 lvItem.state |= LVIS_CUT;
1369 }
1370 if (info.m_stateMask & wxLIST_STATE_DROPHILITED)
1371 {
1372 lvItem.stateMask |= LVIS_DROPHILITED;
1373 if (info.m_state & wxLIST_STATE_DROPHILITED)
1374 lvItem.state |= LVIS_DROPHILITED;
1375 }
1376 if (info.m_stateMask & wxLIST_STATE_FOCUSED)
1377 {
1378 lvItem.stateMask |= LVIS_FOCUSED;
1379 if (info.m_state & wxLIST_STATE_FOCUSED)
1380 lvItem.state |= LVIS_FOCUSED;
1381 }
1382 if (info.m_stateMask & wxLIST_STATE_SELECTED)
1383 {
1384 lvItem.stateMask |= LVIS_SELECTED;
1385 if (info.m_state & wxLIST_STATE_SELECTED)
1386 lvItem.state |= LVIS_SELECTED;
1387 }
1388 }
1389
1390 if (info.m_mask & wxLIST_MASK_TEXT)
1391 {
1392 lvItem.mask |= LVIF_TEXT ;
1393 if ( ctrl->GetWindowStyleFlag() & wxLC_USER_TEXT )
1394 {
1395 lvItem.pszText = LPSTR_TEXTCALLBACK;
1396 }
1397 else
1398 {
1399 lvItem.pszText = (char *) (const char *)info.m_text ;
1400 if ( lvItem.pszText )
1401 lvItem.cchTextMax = info.m_text.Length();
1402 else
1403 lvItem.cchTextMax = 0;
1404 }
1405 }
1406 if (info.m_mask & wxLIST_MASK_IMAGE)
1407 lvItem.mask |= LVIF_IMAGE ;
1408 if (info.m_mask & wxLIST_MASK_DATA)
1409 lvItem.mask |= LVIF_PARAM ;
1410 }
1411
1412 // List event
1413 IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxCommandEvent)
1414
1415 wxListEvent::wxListEvent(wxEventType commandType, int id):
1416 wxCommandEvent(commandType, id)
1417 {
1418 m_code = 0;
1419 m_itemIndex = 0;
1420 m_col = 0;
1421 m_cancelled = FALSE;
1422 }
1423
1424 #endif
1425