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