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