]> git.saurik.com Git - wxWidgets.git/blob - src/msw/listctrl.cpp
Added wxTE_PROCESS_TAB
[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/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 | LVS_SHOWSELALWAYS ;
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_DATA)
486 lvItem.mask |= LVIF_PARAM ;
487
488 if ( info.m_mask & wxLIST_MASK_STATE )
489 {
490 lvItem.mask |= LVIF_STATE;
491 // the other bits are hardly interesting anyhow
492 lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
493 }
494
495 bool success = ListView_GetItem((HWND)GetHWND(), &lvItem) != 0;
496 if ( !success )
497 {
498 wxLogError(_("Couldn't retrieve information about list control item %d."),
499 lvItem.iItem);
500 }
501 else
502 {
503 wxConvertFromMSWListItem(this, info, lvItem);
504 }
505
506 if (lvItem.pszText)
507 delete[] lvItem.pszText;
508
509 return success;
510 }
511
512 // Sets information about the item
513 bool wxListCtrl::SetItem(wxListItem& info)
514 {
515 LV_ITEM item;
516 wxConvertToMSWListItem(this, info, item);
517 item.cchTextMax = 0;
518 return (ListView_SetItem((HWND) GetHWND(), &item) != 0);
519 }
520
521 long wxListCtrl::SetItem(long index, int col, const wxString& label, int imageId)
522 {
523 wxListItem info;
524 info.m_text = label;
525 info.m_mask = wxLIST_MASK_TEXT;
526 info.m_itemId = index;
527 info.m_col = col;
528 if ( imageId > -1 )
529 {
530 info.m_image = imageId;
531 info.m_mask |= wxLIST_MASK_IMAGE;
532 }
533 return SetItem(info);
534 }
535
536
537 // Gets the item state
538 int wxListCtrl::GetItemState(long item, long stateMask) const
539 {
540 wxListItem info;
541
542 info.m_mask = wxLIST_MASK_STATE ;
543 info.m_stateMask = stateMask;
544 info.m_itemId = item;
545
546 if (!GetItem(info))
547 return 0;
548
549 return info.m_state;
550 }
551
552 // Sets the item state
553 bool wxListCtrl::SetItemState(long item, long state, long stateMask)
554 {
555 wxListItem info;
556
557 info.m_mask = wxLIST_MASK_STATE ;
558 info.m_state = state;
559 info.m_stateMask = stateMask;
560 info.m_itemId = item;
561
562 return SetItem(info);
563 }
564
565 // Sets the item image
566 bool wxListCtrl::SetItemImage(long item, int image, int selImage)
567 {
568 wxListItem info;
569
570 info.m_mask = wxLIST_MASK_IMAGE ;
571 info.m_image = image;
572 info.m_itemId = item;
573
574 return SetItem(info);
575 }
576
577 // Gets the item text
578 wxString wxListCtrl::GetItemText(long item) const
579 {
580 wxListItem info;
581
582 info.m_mask = wxLIST_MASK_TEXT ;
583 info.m_itemId = item;
584
585 if (!GetItem(info))
586 return wxString("");
587 return info.m_text;
588 }
589
590 // Sets the item text
591 void wxListCtrl::SetItemText(long item, const wxString& str)
592 {
593 wxListItem info;
594
595 info.m_mask = wxLIST_MASK_TEXT ;
596 info.m_itemId = item;
597 info.m_text = str;
598
599 SetItem(info);
600 }
601
602 // Gets the item data
603 long wxListCtrl::GetItemData(long item) const
604 {
605 wxListItem info;
606
607 info.m_mask = wxLIST_MASK_DATA ;
608 info.m_itemId = item;
609
610 if (!GetItem(info))
611 return 0;
612 return info.m_data;
613 }
614
615 // Sets the item data
616 bool wxListCtrl::SetItemData(long item, long data)
617 {
618 wxListItem info;
619
620 info.m_mask = wxLIST_MASK_DATA ;
621 info.m_itemId = item;
622 info.m_data = data;
623
624 return SetItem(info);
625 }
626
627 // Gets the item rectangle
628 bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const
629 {
630 RECT rect2;
631
632 int code2 = LVIR_BOUNDS;
633 if ( code == wxLIST_RECT_BOUNDS )
634 code2 = LVIR_BOUNDS;
635 else if ( code == wxLIST_RECT_ICON )
636 code2 = LVIR_ICON;
637 else if ( code == wxLIST_RECT_LABEL )
638 code2 = LVIR_LABEL;
639
640 bool success = (ListView_GetItemRect((HWND) GetHWND(), (int) item, &rect2, code2) != 0);
641
642 rect.x = rect2.left;
643 rect.y = rect2.top;
644 rect.width = rect2.right - rect2.left;
645 rect.height = rect2.bottom - rect2.left;
646 return success;
647 }
648
649 // Gets the item position
650 bool wxListCtrl::GetItemPosition(long item, wxPoint& pos) const
651 {
652 POINT pt;
653
654 bool success = (ListView_GetItemPosition((HWND) GetHWND(), (int) item, &pt) != 0);
655
656 pos.x = pt.x; pos.y = pt.y;
657 return success;
658 }
659
660 // Sets the item position.
661 bool wxListCtrl::SetItemPosition(long item, const wxPoint& pos)
662 {
663 return (ListView_SetItemPosition((HWND) GetHWND(), (int) item, pos.x, pos.y) != 0);
664 }
665
666 // Gets the number of items in the list control
667 int wxListCtrl::GetItemCount(void) const
668 {
669 return ListView_GetItemCount((HWND) GetHWND());
670 }
671
672 // Retrieves the spacing between icons in pixels.
673 // If small is TRUE, gets the spacing for the small icon
674 // view, otherwise the large icon view.
675 int wxListCtrl::GetItemSpacing(bool isSmall) const
676 {
677 return ListView_GetItemSpacing((HWND) GetHWND(), (BOOL) isSmall);
678 }
679
680 // Gets the number of selected items in the list control
681 int wxListCtrl::GetSelectedItemCount(void) const
682 {
683 return ListView_GetSelectedCount((HWND) GetHWND());
684 }
685
686 // Gets the text colour of the listview
687 wxColour wxListCtrl::GetTextColour(void) const
688 {
689 COLORREF ref = ListView_GetTextColor((HWND) GetHWND());
690 wxColour col(GetRValue(ref), GetGValue(ref), GetBValue(ref));
691 return col;
692 }
693
694 // Sets the text colour of the listview
695 void wxListCtrl::SetTextColour(const wxColour& col)
696 {
697 ListView_SetTextColor((HWND) GetHWND(), PALETTERGB(col.Red(), col.Blue(), col.Green()));
698 }
699
700 // Gets the index of the topmost visible item when in
701 // list or report view
702 long wxListCtrl::GetTopItem(void) const
703 {
704 return (long) ListView_GetTopIndex((HWND) GetHWND());
705 }
706
707 // Searches for an item, starting from 'item'.
708 // 'geometry' is one of
709 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
710 // 'state' is a state bit flag, one or more of
711 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
712 // item can be -1 to find the first item that matches the
713 // specified flags.
714 // Returns the item or -1 if unsuccessful.
715 long wxListCtrl::GetNextItem(long item, int geom, int state) const
716 {
717 long flags = 0;
718
719 if ( geom == wxLIST_NEXT_ABOVE )
720 flags |= LVNI_ABOVE;
721 if ( geom == wxLIST_NEXT_ALL )
722 flags |= LVNI_ALL;
723 if ( geom == wxLIST_NEXT_BELOW )
724 flags |= LVNI_BELOW;
725 if ( geom == wxLIST_NEXT_LEFT )
726 flags |= LVNI_TOLEFT;
727 if ( geom == wxLIST_NEXT_RIGHT )
728 flags |= LVNI_TORIGHT;
729
730 if ( state & wxLIST_STATE_CUT )
731 flags |= LVNI_CUT;
732 if ( state & wxLIST_STATE_DROPHILITED )
733 flags |= LVNI_DROPHILITED;
734 if ( state & wxLIST_STATE_FOCUSED )
735 flags |= LVNI_FOCUSED;
736 if ( state & wxLIST_STATE_SELECTED )
737 flags |= LVNI_SELECTED;
738
739 return (long) ListView_GetNextItem((HWND) GetHWND(), item, flags);
740 }
741
742
743 wxImageList *wxListCtrl::GetImageList(int which) const
744 {
745 if ( which == wxIMAGE_LIST_NORMAL )
746 {
747 return m_imageListNormal;
748 }
749 else if ( which == wxIMAGE_LIST_SMALL )
750 {
751 return m_imageListSmall;
752 }
753 else if ( which == wxIMAGE_LIST_STATE )
754 {
755 return m_imageListState;
756 }
757 return NULL;
758 }
759
760 void wxListCtrl::SetImageList(wxImageList *imageList, int which)
761 {
762 int flags = 0;
763 if ( which == wxIMAGE_LIST_NORMAL )
764 {
765 flags = LVSIL_NORMAL;
766 m_imageListNormal = imageList;
767 }
768 else if ( which == wxIMAGE_LIST_SMALL )
769 {
770 flags = LVSIL_SMALL;
771 m_imageListSmall = imageList;
772 }
773 else if ( which == wxIMAGE_LIST_STATE )
774 {
775 flags = LVSIL_STATE;
776 m_imageListState = imageList;
777 }
778 ListView_SetImageList((HWND) GetHWND(), (HIMAGELIST) imageList ? imageList->GetHIMAGELIST() : 0, flags);
779 }
780
781 // Operations
782 ////////////////////////////////////////////////////////////////////////////
783
784 // Arranges the items
785 bool wxListCtrl::Arrange(int flag)
786 {
787 UINT code = 0;
788 if ( flag == wxLIST_ALIGN_LEFT )
789 code = LVA_ALIGNLEFT;
790 else if ( flag == wxLIST_ALIGN_TOP )
791 code = LVA_ALIGNTOP;
792 else if ( flag == wxLIST_ALIGN_DEFAULT )
793 code = LVA_DEFAULT;
794 else if ( flag == wxLIST_ALIGN_SNAP_TO_GRID )
795 code = LVA_SNAPTOGRID;
796
797 return (ListView_Arrange((HWND) GetHWND(), code) != 0);
798 }
799
800 // Deletes an item
801 bool wxListCtrl::DeleteItem(long item)
802 {
803 return (ListView_DeleteItem((HWND) GetHWND(), (int) item) != 0);
804 }
805
806 // Deletes all items
807 bool wxListCtrl::DeleteAllItems(void)
808 {
809 return (ListView_DeleteAllItems((HWND) GetHWND()) != 0);
810 }
811
812 // Deletes all items
813 bool wxListCtrl::DeleteAllColumns(void)
814 {
815 int i;
816 for ( i = 0; i < m_colCount; i++)
817 {
818 if (ListView_DeleteColumn((HWND) GetHWND(), 0) != 0)
819 m_colCount --;
820 }
821 return (m_colCount == 0);
822 }
823
824 // Deletes a column
825 bool wxListCtrl::DeleteColumn(int col)
826 {
827 bool success = (ListView_DeleteColumn((HWND) GetHWND(), col) != 0);
828
829 if ( success && (m_colCount > 0) )
830 m_colCount --;
831 return success;
832 }
833
834 // Clears items, and columns if there are any.
835 void wxListCtrl::ClearAll(void)
836 {
837 DeleteAllItems();
838 if ( m_colCount > 0 )
839 DeleteAllColumns();
840 }
841
842 wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass)
843 {
844 wxASSERT( (textControlClass->IsKindOf(CLASSINFO(wxTextCtrl))) );
845
846 HWND hWnd = (HWND) ListView_EditLabel((HWND) GetHWND(), item);
847
848 if (m_textCtrl)
849 {
850 m_textCtrl->UnsubclassWin();
851 m_textCtrl->SetHWND(0);
852 delete m_textCtrl;
853 m_textCtrl = NULL;
854 }
855
856 m_textCtrl = (wxTextCtrl*) textControlClass->CreateObject();
857 m_textCtrl->SetHWND((WXHWND) hWnd);
858 m_textCtrl->SubclassWin((WXHWND) hWnd);
859
860 return m_textCtrl;
861 }
862
863 // End label editing, optionally cancelling the edit
864 bool wxListCtrl::EndEditLabel(bool cancel)
865 {
866 wxFAIL;
867
868 /* I don't know how to implement this: there's no such macro as ListView_EndEditLabelNow.
869 * ???
870 bool success = (ListView_EndEditLabelNow((HWND) GetHWND(), cancel) != 0);
871
872 if (m_textCtrl)
873 {
874 m_textCtrl->UnsubclassWin();
875 m_textCtrl->SetHWND(0);
876 delete m_textCtrl;
877 m_textCtrl = NULL;
878 }
879 return success;
880 */
881 return FALSE;
882 }
883
884
885 // Ensures this item is visible
886 bool wxListCtrl::EnsureVisible(long item)
887 {
888 return (ListView_EnsureVisible((HWND) GetHWND(), (int) item, FALSE) != 0);
889 }
890
891 // Find an item whose label matches this string, starting from the item after 'start'
892 // or the beginning if 'start' is -1.
893 long wxListCtrl::FindItem(long start, const wxString& str, bool partial)
894 {
895 LV_FINDINFO findInfo;
896
897 findInfo.flags = LVFI_STRING;
898 if ( partial )
899 findInfo.flags |= LVFI_STRING;
900 findInfo.psz = WXSTRINGCAST str;
901
902 return ListView_FindItem((HWND) GetHWND(), (int) start, & findInfo);
903 }
904
905 // Find an item whose data matches this data, starting from the item after 'start'
906 // or the beginning if 'start' is -1.
907 long wxListCtrl::FindItem(long start, long data)
908 {
909 LV_FINDINFO findInfo;
910
911 findInfo.flags = LVFI_PARAM;
912 findInfo.lParam = data;
913
914 return ListView_FindItem((HWND) GetHWND(), (int) start, & findInfo);
915 }
916
917 // Find an item nearest this position in the specified direction, starting from
918 // the item after 'start' or the beginning if 'start' is -1.
919 long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction)
920 {
921 LV_FINDINFO findInfo;
922
923 findInfo.flags = LVFI_NEARESTXY;
924 findInfo.pt.x = pt.x;
925 findInfo.pt.y = pt.y;
926 findInfo.vkDirection = VK_RIGHT;
927
928 if ( direction == wxLIST_FIND_UP )
929 findInfo.vkDirection = VK_UP;
930 else if ( direction == wxLIST_FIND_DOWN )
931 findInfo.vkDirection = VK_DOWN;
932 else if ( direction == wxLIST_FIND_LEFT )
933 findInfo.vkDirection = VK_LEFT;
934 else if ( direction == wxLIST_FIND_RIGHT )
935 findInfo.vkDirection = VK_RIGHT;
936
937 return ListView_FindItem((HWND) GetHWND(), (int) start, & findInfo);
938 }
939
940 // Determines which item (if any) is at the specified point,
941 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
942 long wxListCtrl::HitTest(const wxPoint& point, int& flags)
943 {
944 LV_HITTESTINFO hitTestInfo;
945 hitTestInfo.pt.x = (int) point.x;
946 hitTestInfo.pt.y = (int) point.y;
947
948 ListView_HitTest((HWND) GetHWND(), & hitTestInfo);
949
950 flags = 0;
951 if ( hitTestInfo.flags & LVHT_ABOVE )
952 flags |= wxLIST_HITTEST_ABOVE;
953 if ( hitTestInfo.flags & LVHT_BELOW )
954 flags |= wxLIST_HITTEST_BELOW;
955 if ( hitTestInfo.flags & LVHT_NOWHERE )
956 flags |= wxLIST_HITTEST_NOWHERE;
957 if ( hitTestInfo.flags & LVHT_ONITEMICON )
958 flags |= wxLIST_HITTEST_ONITEMICON;
959 if ( hitTestInfo.flags & LVHT_ONITEMLABEL )
960 flags |= wxLIST_HITTEST_ONITEMLABEL;
961 if ( hitTestInfo.flags & LVHT_ONITEMSTATEICON )
962 flags |= wxLIST_HITTEST_ONITEMSTATEICON;
963 if ( hitTestInfo.flags & LVHT_TOLEFT )
964 flags |= wxLIST_HITTEST_TOLEFT;
965 if ( hitTestInfo.flags & LVHT_TORIGHT )
966 flags |= wxLIST_HITTEST_TORIGHT;
967
968 return (long) hitTestInfo.iItem ;
969 }
970
971 // Inserts an item, returning the index of the new item if successful,
972 // -1 otherwise.
973 long wxListCtrl::InsertItem(wxListItem& info)
974 {
975 LV_ITEM item;
976 wxConvertToMSWListItem(this, info, item);
977
978 return (long) ListView_InsertItem((HWND) GetHWND(), & item);
979 }
980
981 long wxListCtrl::InsertItem(long index, const wxString& label)
982 {
983 wxListItem info;
984 info.m_text = label;
985 info.m_mask = wxLIST_MASK_TEXT;
986 info.m_itemId = index;
987 return InsertItem(info);
988 }
989
990 // Inserts an image item
991 long wxListCtrl::InsertItem(long index, int imageIndex)
992 {
993 wxListItem info;
994 info.m_image = imageIndex;
995 info.m_mask = wxLIST_MASK_IMAGE;
996 info.m_itemId = index;
997 return InsertItem(info);
998 }
999
1000 // Inserts an image/string item
1001 long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex)
1002 {
1003 wxListItem info;
1004 info.m_image = imageIndex;
1005 info.m_text = label;
1006 info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT;
1007 info.m_itemId = index;
1008 return InsertItem(info);
1009 }
1010
1011 // For list view mode (only), inserts a column.
1012 long wxListCtrl::InsertColumn(long col, wxListItem& item)
1013 {
1014 LV_COLUMN lvCol;
1015 lvCol.mask = 0;
1016 lvCol.fmt = 0;
1017 lvCol.pszText = NULL;
1018
1019 if ( item.m_mask & wxLIST_MASK_TEXT )
1020 {
1021 lvCol.mask |= LVCF_TEXT;
1022 lvCol.pszText = WXSTRINGCAST item.m_text;
1023 lvCol.cchTextMax = 0; // Ignored
1024 }
1025 if ( item.m_mask & wxLIST_MASK_FORMAT )
1026 {
1027 lvCol.mask |= LVCF_FMT;
1028
1029 if ( item.m_format == wxLIST_FORMAT_LEFT )
1030 lvCol.fmt = LVCFMT_LEFT;
1031 if ( item.m_format == wxLIST_FORMAT_RIGHT )
1032 lvCol.fmt = LVCFMT_RIGHT;
1033 if ( item.m_format == wxLIST_FORMAT_CENTRE )
1034 lvCol.fmt = LVCFMT_CENTER;
1035 }
1036
1037 if ( item.m_mask & wxLIST_MASK_WIDTH )
1038 {
1039 lvCol.mask |= LVCF_WIDTH;
1040 lvCol.cx = item.m_width;
1041
1042 if ( lvCol.cx == wxLIST_AUTOSIZE)
1043 lvCol.cx = LVSCW_AUTOSIZE;
1044 else if ( lvCol.cx == wxLIST_AUTOSIZE_USEHEADER)
1045 lvCol.cx = LVSCW_AUTOSIZE_USEHEADER;
1046 }
1047 lvCol.mask |= LVCF_SUBITEM;
1048 lvCol.iSubItem = col;
1049
1050 bool success = (ListView_InsertColumn((HWND) GetHWND(), col, & lvCol) != 0);
1051 if ( success )
1052 m_colCount ++;
1053 return success;
1054 }
1055
1056 long wxListCtrl::InsertColumn(long col, const wxString& heading, int format,
1057 int width)
1058 {
1059 wxListItem item;
1060 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
1061 item.m_text = heading;
1062 if ( width > -1 )
1063 {
1064 item.m_mask |= wxLIST_MASK_WIDTH;
1065 item.m_width = width;
1066 }
1067 item.m_format = format;
1068
1069 return InsertColumn(col, item);
1070 }
1071
1072 // Scrolls the list control. If in icon, small icon or report view mode,
1073 // x specifies the number of pixels to scroll. If in list view mode, x
1074 // specifies the number of columns to scroll.
1075 // If in icon, small icon or list view mode, y specifies the number of pixels
1076 // to scroll. If in report view mode, y specifies the number of lines to scroll.
1077 bool wxListCtrl::ScrollList(int dx, int dy)
1078 {
1079 return (ListView_Scroll((HWND) GetHWND(), dx, dy) != 0);
1080 }
1081
1082 // Sort items.
1083
1084 // fn is a function which takes 3 long arguments: item1, item2, data.
1085 // item1 is the long data associated with a first item (NOT the index).
1086 // item2 is the long data associated with a second item (NOT the index).
1087 // data is the same value as passed to SortItems.
1088 // The return value is a negative number if the first item should precede the second
1089 // item, a positive number of the second item should precede the first,
1090 // or zero if the two items are equivalent.
1091
1092 // data is arbitrary data to be passed to the sort function.
1093 bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data)
1094 {
1095 return (ListView_SortItems((HWND) GetHWND(), (PFNLVCOMPARE) fn, data) != 0);
1096 }
1097
1098 bool wxListCtrl::MSWCommand(WXUINT cmd, WXWORD id)
1099 {
1100 if (cmd == EN_UPDATE)
1101 {
1102 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, id);
1103 event.SetEventObject( this );
1104 ProcessCommand(event);
1105 return TRUE;
1106 }
1107 else if (cmd == EN_KILLFOCUS)
1108 {
1109 wxCommandEvent event(wxEVT_KILL_FOCUS, id);
1110 event.SetEventObject( this );
1111 ProcessCommand(event);
1112 return TRUE;
1113 }
1114 else return FALSE;
1115 }
1116
1117 bool wxListCtrl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result)
1118 {
1119 wxListEvent event(wxEVT_NULL, m_windowId);
1120 wxEventType eventType = wxEVT_NULL;
1121 NMHDR *hdr1 = (NMHDR *) lParam;
1122 switch ( hdr1->code )
1123 {
1124 case LVN_BEGINRDRAG:
1125 eventType = wxEVT_COMMAND_LIST_BEGIN_RDRAG;
1126 // fall through
1127
1128 case LVN_BEGINDRAG:
1129 if ( eventType == wxEVT_NULL )
1130 {
1131 eventType = wxEVT_COMMAND_LIST_BEGIN_DRAG;
1132 }
1133
1134 {
1135 NM_LISTVIEW *hdr = (NM_LISTVIEW *)lParam;
1136 event.m_itemIndex = hdr->iItem;
1137 event.m_pointDrag.x = hdr->ptAction.x;
1138 event.m_pointDrag.y = hdr->ptAction.y;
1139 }
1140 break;
1141
1142 case LVN_BEGINLABELEDIT:
1143 {
1144 eventType = wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT;
1145 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1146 wxConvertFromMSWListItem(this, event.m_item, info->item, (HWND) GetHWND());
1147 break;
1148 }
1149
1150 case LVN_COLUMNCLICK:
1151 {
1152 eventType = wxEVT_COMMAND_LIST_COL_CLICK;
1153 NM_LISTVIEW* hdr = (NM_LISTVIEW*)lParam;
1154 event.m_itemIndex = -1;
1155 event.m_col = hdr->iSubItem;
1156 break;
1157 }
1158 case LVN_DELETEALLITEMS:
1159 {
1160 eventType = wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS;
1161 // NM_LISTVIEW* hdr = (NM_LISTVIEW*)lParam;
1162 event.m_itemIndex = -1;
1163 break;
1164 }
1165 case LVN_DELETEITEM:
1166 {
1167 eventType = wxEVT_COMMAND_LIST_DELETE_ITEM;
1168 NM_LISTVIEW* hdr = (NM_LISTVIEW*)lParam;
1169 event.m_itemIndex = hdr->iItem;
1170 break;
1171 }
1172 case LVN_ENDLABELEDIT:
1173 {
1174 eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT;
1175 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1176 wxConvertFromMSWListItem(this, event.m_item, info->item, (HWND) GetHWND());
1177 if ( info->item.pszText == NULL || info->item.iItem == -1 )
1178 event.m_cancelled = TRUE;
1179 break;
1180 }
1181 case LVN_GETDISPINFO:
1182 {
1183 // return FALSE;
1184 // TODO: some text buffering here, I think
1185 // TODO: API for getting Windows to retrieve values
1186 // on demand.
1187 eventType = wxEVT_COMMAND_LIST_GET_INFO;
1188 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1189 wxConvertFromMSWListItem(this, event.m_item, info->item, (HWND) GetHWND());
1190 break;
1191 }
1192 case LVN_INSERTITEM:
1193 {
1194 eventType = wxEVT_COMMAND_LIST_INSERT_ITEM;
1195 NM_LISTVIEW* hdr = (NM_LISTVIEW*)lParam;
1196 event.m_itemIndex = hdr->iItem;
1197 break;
1198 }
1199 case LVN_ITEMCHANGED:
1200 {
1201 // This needs to be sent to wxListCtrl as a rather more
1202 // concrete event. For now, just detect a selection
1203 // or deselection.
1204 NM_LISTVIEW* hdr = (NM_LISTVIEW*)lParam;
1205 if ( (hdr->uNewState & LVIS_SELECTED) && !(hdr->uOldState & LVIS_SELECTED) )
1206 {
1207 eventType = wxEVT_COMMAND_LIST_ITEM_SELECTED;
1208 event.m_itemIndex = hdr->iItem;
1209 }
1210 else if ( !(hdr->uNewState & LVIS_SELECTED) && (hdr->uOldState & LVIS_SELECTED) )
1211 {
1212 eventType = wxEVT_COMMAND_LIST_ITEM_DESELECTED;
1213 event.m_itemIndex = hdr->iItem;
1214 }
1215 else
1216 return FALSE;
1217 break;
1218 }
1219 case LVN_KEYDOWN:
1220 {
1221 eventType = wxEVT_COMMAND_LIST_KEY_DOWN;
1222 LV_KEYDOWN *info = (LV_KEYDOWN *)lParam;
1223 event.m_code = wxCharCodeMSWToWX(info->wVKey);
1224 break;
1225 }
1226 case LVN_SETDISPINFO:
1227 {
1228 eventType = wxEVT_COMMAND_LIST_SET_INFO;
1229 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1230 wxConvertFromMSWListItem(this, event.m_item, info->item, (HWND) GetHWND());
1231 break;
1232 }
1233
1234 default :
1235 return wxControl::MSWNotify(wParam, lParam, result);
1236 }
1237
1238 event.SetEventObject( this );
1239 event.SetEventType(eventType);
1240
1241 if ( !GetEventHandler()->ProcessEvent(event) )
1242 return FALSE;
1243
1244 if (hdr1->code == LVN_GETDISPINFO)
1245 {
1246 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1247 if ( info->item.mask & LVIF_TEXT )
1248 {
1249 if ( !event.m_item.m_text.IsNull() )
1250 {
1251 info->item.pszText = AddPool(event.m_item.m_text);
1252 info->item.cchTextMax = strlen(info->item.pszText) + 1;
1253 }
1254 }
1255 // wxConvertToMSWListItem(this, event.m_item, info->item);
1256 }
1257
1258 *result = !event.IsAllowed();
1259
1260 return TRUE;
1261 }
1262
1263 char *wxListCtrl::AddPool(const wxString& str)
1264 {
1265 // Remove the first element if 3 strings exist
1266 if ( m_stringPool.Number() == 3 )
1267 {
1268 wxNode *node = m_stringPool.First();
1269 delete[] (char *)node->Data();
1270 delete node;
1271 }
1272 wxNode *node = m_stringPool.Add((char *) (const char *)str);
1273 return (char *)node->Data();
1274 }
1275
1276 // List item structure
1277 wxListItem::wxListItem(void)
1278 {
1279 m_mask = 0;
1280 m_itemId = 0;
1281 m_col = 0;
1282 m_state = 0;
1283 m_stateMask = 0;
1284 m_image = 0;
1285 m_data = 0;
1286
1287 m_format = wxLIST_FORMAT_CENTRE;
1288 m_width = 0;
1289 }
1290
1291 static void wxConvertFromMSWListItem(const wxListCtrl *ctrl, wxListItem& info, LV_ITEM& lvItem, HWND getFullInfo)
1292 {
1293 info.m_data = lvItem.lParam;
1294 info.m_mask = 0;
1295 info.m_state = 0;
1296 info.m_stateMask = 0;
1297 info.m_itemId = lvItem.iItem;
1298
1299 long oldMask = lvItem.mask;
1300
1301 bool needText = FALSE;
1302 if (getFullInfo != 0)
1303 {
1304 if ( lvItem.mask & LVIF_TEXT )
1305 needText = FALSE;
1306 else
1307 needText = TRUE;
1308
1309 if ( needText )
1310 {
1311 lvItem.pszText = new char[513];
1312 lvItem.cchTextMax = 512;
1313 }
1314 // lvItem.mask |= TVIF_HANDLE | TVIF_STATE | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM ;
1315 lvItem.mask |= LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM ;
1316 ::SendMessage(getFullInfo, LVM_GETITEM, 0, (LPARAM)& lvItem) ;
1317 }
1318
1319 if ( lvItem.mask & LVIF_STATE )
1320 {
1321 info.m_mask |= wxLIST_MASK_STATE;
1322
1323 if ( lvItem.stateMask & LVIS_CUT)
1324 {
1325 info.m_stateMask |= wxLIST_STATE_CUT ;
1326 if ( lvItem.state & LVIS_CUT )
1327 info.m_state |= wxLIST_STATE_CUT ;
1328 }
1329 if ( lvItem.stateMask & LVIS_DROPHILITED)
1330 {
1331 info.m_stateMask |= wxLIST_STATE_DROPHILITED ;
1332 if ( lvItem.state & LVIS_DROPHILITED )
1333 info.m_state |= wxLIST_STATE_DROPHILITED ;
1334 }
1335 if ( lvItem.stateMask & LVIS_FOCUSED)
1336 {
1337 info.m_stateMask |= wxLIST_STATE_FOCUSED ;
1338 if ( lvItem.state & LVIS_FOCUSED )
1339 info.m_state |= wxLIST_STATE_FOCUSED ;
1340 }
1341 if ( lvItem.stateMask & LVIS_SELECTED)
1342 {
1343 info.m_stateMask |= wxLIST_STATE_SELECTED ;
1344 if ( lvItem.state & LVIS_SELECTED )
1345 info.m_state |= wxLIST_STATE_SELECTED ;
1346 }
1347 }
1348
1349 if ( lvItem.mask & LVIF_TEXT )
1350 {
1351 info.m_mask |= wxLIST_MASK_TEXT;
1352 info.m_text = lvItem.pszText;
1353 }
1354 if ( lvItem.mask & LVIF_IMAGE )
1355 {
1356 info.m_mask |= wxLIST_MASK_IMAGE;
1357 info.m_image = lvItem.iImage;
1358 }
1359 if ( lvItem.mask & LVIF_PARAM )
1360 info.m_mask |= wxLIST_MASK_DATA;
1361 if ( lvItem.mask & LVIF_DI_SETITEM )
1362 info.m_mask |= wxLIST_SET_ITEM;
1363 info.m_col = lvItem.iSubItem;
1364
1365 if (needText)
1366 {
1367 if (lvItem.pszText)
1368 delete[] lvItem.pszText;
1369 }
1370 lvItem.mask = oldMask ;
1371 }
1372
1373 static void wxConvertToMSWListItem(const wxListCtrl *ctrl, wxListItem& info, LV_ITEM& lvItem)
1374 {
1375 lvItem.iItem = (int) info.m_itemId ;
1376
1377 lvItem.iImage = info.m_image ;
1378 lvItem.lParam = info.m_data;
1379 lvItem.stateMask = 0;
1380 lvItem.state = 0;
1381 lvItem.mask = 0;
1382 lvItem.iSubItem = info.m_col;
1383
1384 if (info.m_mask & wxLIST_MASK_STATE)
1385 {
1386 lvItem.mask |= LVIF_STATE ;
1387 if (info.m_stateMask & wxLIST_STATE_CUT)
1388 {
1389 lvItem.stateMask |= LVIS_CUT ;
1390 if (info.m_state & wxLIST_STATE_CUT)
1391 lvItem.state |= LVIS_CUT;
1392 }
1393 if (info.m_stateMask & wxLIST_STATE_DROPHILITED)
1394 {
1395 lvItem.stateMask |= LVIS_DROPHILITED;
1396 if (info.m_state & wxLIST_STATE_DROPHILITED)
1397 lvItem.state |= LVIS_DROPHILITED;
1398 }
1399 if (info.m_stateMask & wxLIST_STATE_FOCUSED)
1400 {
1401 lvItem.stateMask |= LVIS_FOCUSED;
1402 if (info.m_state & wxLIST_STATE_FOCUSED)
1403 lvItem.state |= LVIS_FOCUSED;
1404 }
1405 if (info.m_stateMask & wxLIST_STATE_SELECTED)
1406 {
1407 lvItem.stateMask |= LVIS_SELECTED;
1408 if (info.m_state & wxLIST_STATE_SELECTED)
1409 lvItem.state |= LVIS_SELECTED;
1410 }
1411 }
1412
1413 if (info.m_mask & wxLIST_MASK_TEXT)
1414 {
1415 lvItem.mask |= LVIF_TEXT ;
1416 if ( ctrl->GetWindowStyleFlag() & wxLC_USER_TEXT )
1417 {
1418 lvItem.pszText = LPSTR_TEXTCALLBACK;
1419 }
1420 else
1421 {
1422 lvItem.pszText = (char *) (const char *)info.m_text ;
1423 if ( lvItem.pszText )
1424 lvItem.cchTextMax = info.m_text.Length();
1425 else
1426 lvItem.cchTextMax = 0;
1427 }
1428 }
1429 if (info.m_mask & wxLIST_MASK_IMAGE)
1430 lvItem.mask |= LVIF_IMAGE ;
1431 if (info.m_mask & wxLIST_MASK_DATA)
1432 lvItem.mask |= LVIF_PARAM ;
1433 }
1434
1435 // List event
1436 IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
1437
1438 wxListEvent::wxListEvent(wxEventType commandType, int id)
1439 : wxNotifyEvent(commandType, id)
1440 {
1441 m_code = 0;
1442 m_itemIndex = 0;
1443 m_col = 0;
1444 m_cancelled = FALSE;
1445 }
1446
1447 #endif
1448