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