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