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