]> git.saurik.com Git - wxWidgets.git/blame - src/msw/listctrl.cpp
added test mode to wxLongLongWx which allowed to find the bug in operator*=()
[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
1ee4ead5
VZ
1423 {
1424 eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
1425 NM_LISTVIEW* hdr = (NM_LISTVIEW*)lParam;
1426 event.m_itemIndex = hdr->iItem;
1427 }
edccf428 1428 break;
cb0f56f9
VZ
1429
1430 case NM_RCLICK:
1431 /* TECH NOTE: NM_RCLICK isn't really good enough here. We want to
1432 subclass and check for the actual WM_RBUTTONDOWN message, because
1433 NM_RCLICK waits for the WM_RBUTTONUP message as well before firing off.
1434 We want to have notify events for both down -and- up. */
1435 {
1436 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(), don't do
1437 // anything else
1438 if ( wxControl::MSWOnNotify(idCtrl, lParam, result) ) {
1439 return TRUE;
1440 }
1441
1442 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1443 LV_HITTESTINFO lvhti;
11c7d5b6
VZ
1444 wxZeroMemory(lvhti);
1445
cb0f56f9
VZ
1446 ::GetCursorPos(&(lvhti.pt));
1447 ::ScreenToClient(GetHwnd(),&(lvhti.pt));
1448 if ( ListView_HitTest(GetHwnd(),&lvhti) != -1 )
1449 {
cb0f56f9
VZ
1450 if ( lvhti.flags & LVHT_ONITEM )
1451 {
1452 eventType = wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK;
1453 event.m_itemIndex = lvhti.iItem;
1454 }
9bfa7bfc 1455 }
cb0f56f9
VZ
1456 }
1457 break;
1458
bdc72a22
VZ
1459#if 0
1460 case NM_MCLICK: // ***** THERE IS NO NM_MCLICK. Subclass anyone? ******
1461 {
1462 // if the user processes it in wxEVT_COMMAND_MIDDLE_CLICK(), don't do
1463 // anything else
1464 if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
1465 {
1466 return TRUE;
1467 }
cb0f56f9 1468
bdc72a22
VZ
1469 // else translate it into wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK event
1470 eventType = wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK;
1471 NMITEMACTIVATE* hdr = (NMITEMACTIVATE*)lParam;
1472 event.m_itemIndex = hdr->iItem;
1473 }
1474 break;
1475#endif // 0
1476
6ecfe2ac 1477#if defined(_WIN32_IE) && _WIN32_IE >= 0x300
bdc72a22 1478 case NM_CUSTOMDRAW:
0b5efdc7 1479 {
bdc72a22
VZ
1480 LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
1481 NMCUSTOMDRAW& nmcd = lplvcd->nmcd;
1482 switch( nmcd.dwDrawStage )
1483 {
d62228a6 1484 case CDDS_PREPAINT:
bdc72a22
VZ
1485 // if we've got any items with non standard attributes,
1486 // notify us before painting each item
1487 *result = m_hasAnyAttr ? CDRF_NOTIFYITEMDRAW
1488 : CDRF_DODEFAULT;
1489 return TRUE;
1490
1491 case CDDS_ITEMPREPAINT:
1492 {
d62228a6
VZ
1493 wxListItemAttr *attr =
1494 (wxListItemAttr *)m_attrs.Get(nmcd.dwItemSpec);
1495
1496 if ( !attr )
bdc72a22
VZ
1497 {
1498 // nothing to do for this item
1499 return CDRF_DODEFAULT;
1500 }
1501
d62228a6
VZ
1502 HFONT hFont;
1503 wxColour colText, colBack;
1504 if ( attr->HasFont() )
1505 {
1506 wxFont font = attr->GetFont();
1507 hFont = (HFONT)font.GetResourceHandle();
1508 }
1509 else
1510 {
1511 hFont = 0;
1512 }
1513
1514 if ( attr->HasTextColour() )
1515 {
1516 colText = attr->GetTextColour();
1517 }
1518 else
1519 {
1520 colText = GetTextColour();
1521 }
1522
1523 if ( attr->HasBackgroundColour() )
1524 {
1525 colBack = attr->GetBackgroundColour();
1526 }
1527 else
1528 {
1529 colBack = GetBackgroundColour();
1530 }
1531
1532 // note that if we wanted to set colours for
1533 // individual columns (subitems), we would have
1534 // returned CDRF_NOTIFYSUBITEMREDRAW from here
1535 if ( hFont )
1536 {
1537 ::SelectObject(nmcd.hdc, hFont);
bdc72a22 1538
d62228a6
VZ
1539 *result = CDRF_NEWFONT;
1540 }
1541 else
1542 {
1543 *result = CDRF_DODEFAULT;
1544 }
bdc72a22 1545
d62228a6
VZ
1546 lplvcd->clrText = wxColourToRGB(colText);
1547 lplvcd->clrTextBk = wxColourToRGB(colBack);
bdc72a22
VZ
1548
1549 return TRUE;
1550 }
d62228a6
VZ
1551
1552 default:
1553 *result = CDRF_DODEFAULT;
1554 return TRUE;
bdc72a22 1555 }
0b5efdc7 1556 }
bdc72a22 1557 break;
6ecfe2ac 1558#endif // _WIN32_IE >= 0x300
0b5efdc7 1559
edccf428 1560 default:
a23fd0e1 1561 return wxControl::MSWOnNotify(idCtrl, lParam, result);
acb62b84
VZ
1562 }
1563
bdc72a22
VZ
1564 // process the event
1565 // -----------------
1566
0b5efdc7
VZ
1567 event.SetEventObject( this );
1568 event.SetEventType(eventType);
acb62b84 1569
0b5efdc7
VZ
1570 if ( !GetEventHandler()->ProcessEvent(event) )
1571 return FALSE;
acb62b84 1572
bdc72a22
VZ
1573 // post processing
1574 // ---------------
1575
1576 switch ( (int)nmhdr->code )
acb62b84 1577 {
1ee4ead5 1578 case LVN_GETDISPINFO:
0b5efdc7 1579 {
1ee4ead5
VZ
1580 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1581 if ( info->item.mask & LVIF_TEXT )
1582 {
1583 if ( !event.m_item.m_text.IsNull() )
1584 {
1585 info->item.pszText = AddPool(event.m_item.m_text);
1586 info->item.cchTextMax = wxStrlen(info->item.pszText) + 1;
1587 }
1588 }
1589 // wxConvertToMSWListItem(this, event.m_item, info->item);
1590 break;
0b5efdc7 1591 }
1ee4ead5
VZ
1592 case LVN_ENDLABELEDIT:
1593 {
1594 *result = event.IsAllowed();
1595 return TRUE;
1596 }
1597 default:
1598 break;
acb62b84 1599 }
acb62b84 1600
0b5efdc7 1601 *result = !event.IsAllowed();
fd3f686c 1602
0b5efdc7 1603 return TRUE;
2bda0e17
KB
1604}
1605
837e5743 1606wxChar *wxListCtrl::AddPool(const wxString& str)
2bda0e17 1607{
0b5efdc7
VZ
1608 // Remove the first element if 3 strings exist
1609 if ( m_stringPool.Number() == 3 )
1610 {
1611 wxNode *node = m_stringPool.First();
1612 delete[] (char *)node->Data();
1613 delete node;
1614 }
837e5743
OK
1615 wxNode *node = m_stringPool.Add(WXSTRINGCAST str);
1616 return (wxChar *)node->Data();
2bda0e17
KB
1617}
1618
edccf428
VZ
1619// ----------------------------------------------------------------------------
1620// wxListItem
1621// ----------------------------------------------------------------------------
1622
2bda0e17 1623// List item structure
0b5efdc7 1624wxListItem::wxListItem()
2bda0e17
KB
1625{
1626 m_mask = 0;
1627 m_itemId = 0;
1628 m_col = 0;
1629 m_state = 0;
1630 m_stateMask = 0;
1631 m_image = 0;
0b5efdc7 1632 m_data = 0;
2bda0e17 1633
0b5efdc7
VZ
1634 m_format = wxLIST_FORMAT_CENTRE;
1635 m_width = 0;
bdc72a22
VZ
1636
1637 m_attr = NULL;
2bda0e17
KB
1638}
1639
9b00bb16
RR
1640void wxListItem::Clear()
1641{
1642 m_mask = 0;
1643 m_itemId = 0;
1644 m_col = 0;
1645 m_state = 0;
1646 m_stateMask = 0;
1647 m_image = 0;
1648 m_data = 0;
1649 m_format = wxLIST_FORMAT_CENTRE;
1650 m_width = 0;
1651 m_text = wxEmptyString;
1652
1653 if (m_attr) delete m_attr;
1654 m_attr = NULL;
1655}
1656
1657void wxListItem::ClearAttributes()
1658{
1659 if (m_attr) delete m_attr;
1660 m_attr = NULL;
1661}
1662
2bda0e17
KB
1663static void wxConvertFromMSWListItem(const wxListCtrl *ctrl, wxListItem& info, LV_ITEM& lvItem, HWND getFullInfo)
1664{
0b5efdc7
VZ
1665 info.m_data = lvItem.lParam;
1666 info.m_mask = 0;
1667 info.m_state = 0;
1668 info.m_stateMask = 0;
1669 info.m_itemId = lvItem.iItem;
acb62b84 1670
0b5efdc7 1671 long oldMask = lvItem.mask;
acb62b84 1672
0b5efdc7
VZ
1673 bool needText = FALSE;
1674 if (getFullInfo != 0)
acb62b84 1675 {
0b5efdc7
VZ
1676 if ( lvItem.mask & LVIF_TEXT )
1677 needText = FALSE;
1678 else
1679 needText = TRUE;
acb62b84 1680
0b5efdc7
VZ
1681 if ( needText )
1682 {
837e5743 1683 lvItem.pszText = new wxChar[513];
0b5efdc7
VZ
1684 lvItem.cchTextMax = 512;
1685 }
edccf428
VZ
1686 // lvItem.mask |= TVIF_HANDLE | TVIF_STATE | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
1687 lvItem.mask |= LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
1688 ::SendMessage(getFullInfo, LVM_GETITEM, 0, (LPARAM)& lvItem);
0b5efdc7 1689 }
acb62b84 1690
0b5efdc7 1691 if ( lvItem.mask & LVIF_STATE )
acb62b84 1692 {
0b5efdc7
VZ
1693 info.m_mask |= wxLIST_MASK_STATE;
1694
1695 if ( lvItem.stateMask & LVIS_CUT)
1696 {
edccf428 1697 info.m_stateMask |= wxLIST_STATE_CUT;
0b5efdc7 1698 if ( lvItem.state & LVIS_CUT )
edccf428 1699 info.m_state |= wxLIST_STATE_CUT;
0b5efdc7
VZ
1700 }
1701 if ( lvItem.stateMask & LVIS_DROPHILITED)
1702 {
edccf428 1703 info.m_stateMask |= wxLIST_STATE_DROPHILITED;
0b5efdc7 1704 if ( lvItem.state & LVIS_DROPHILITED )
edccf428 1705 info.m_state |= wxLIST_STATE_DROPHILITED;
0b5efdc7
VZ
1706 }
1707 if ( lvItem.stateMask & LVIS_FOCUSED)
1708 {
edccf428 1709 info.m_stateMask |= wxLIST_STATE_FOCUSED;
0b5efdc7 1710 if ( lvItem.state & LVIS_FOCUSED )
edccf428 1711 info.m_state |= wxLIST_STATE_FOCUSED;
0b5efdc7
VZ
1712 }
1713 if ( lvItem.stateMask & LVIS_SELECTED)
1714 {
edccf428 1715 info.m_stateMask |= wxLIST_STATE_SELECTED;
0b5efdc7 1716 if ( lvItem.state & LVIS_SELECTED )
edccf428 1717 info.m_state |= wxLIST_STATE_SELECTED;
0b5efdc7 1718 }
acb62b84 1719 }
0b5efdc7
VZ
1720
1721 if ( lvItem.mask & LVIF_TEXT )
acb62b84 1722 {
0b5efdc7
VZ
1723 info.m_mask |= wxLIST_MASK_TEXT;
1724 info.m_text = lvItem.pszText;
acb62b84 1725 }
0b5efdc7 1726 if ( lvItem.mask & LVIF_IMAGE )
acb62b84 1727 {
0b5efdc7
VZ
1728 info.m_mask |= wxLIST_MASK_IMAGE;
1729 info.m_image = lvItem.iImage;
acb62b84 1730 }
0b5efdc7
VZ
1731 if ( lvItem.mask & LVIF_PARAM )
1732 info.m_mask |= wxLIST_MASK_DATA;
1733 if ( lvItem.mask & LVIF_DI_SETITEM )
1734 info.m_mask |= wxLIST_SET_ITEM;
1735 info.m_col = lvItem.iSubItem;
1736
1737 if (needText)
acb62b84 1738 {
0b5efdc7
VZ
1739 if (lvItem.pszText)
1740 delete[] lvItem.pszText;
acb62b84 1741 }
edccf428 1742 lvItem.mask = oldMask;
2bda0e17
KB
1743}
1744
1745static void wxConvertToMSWListItem(const wxListCtrl *ctrl, wxListItem& info, LV_ITEM& lvItem)
1746{
edccf428 1747 lvItem.iItem = (int) info.m_itemId;
acb62b84 1748
edccf428 1749 lvItem.iImage = info.m_image;
0b5efdc7
VZ
1750 lvItem.lParam = info.m_data;
1751 lvItem.stateMask = 0;
1752 lvItem.state = 0;
1753 lvItem.mask = 0;
1754 lvItem.iSubItem = info.m_col;
acb62b84 1755
0b5efdc7 1756 if (info.m_mask & wxLIST_MASK_STATE)
acb62b84 1757 {
edccf428 1758 lvItem.mask |= LVIF_STATE;
0b5efdc7
VZ
1759 if (info.m_stateMask & wxLIST_STATE_CUT)
1760 {
edccf428 1761 lvItem.stateMask |= LVIS_CUT;
0b5efdc7
VZ
1762 if (info.m_state & wxLIST_STATE_CUT)
1763 lvItem.state |= LVIS_CUT;
1764 }
1765 if (info.m_stateMask & wxLIST_STATE_DROPHILITED)
1766 {
1767 lvItem.stateMask |= LVIS_DROPHILITED;
1768 if (info.m_state & wxLIST_STATE_DROPHILITED)
1769 lvItem.state |= LVIS_DROPHILITED;
1770 }
1771 if (info.m_stateMask & wxLIST_STATE_FOCUSED)
1772 {
1773 lvItem.stateMask |= LVIS_FOCUSED;
1774 if (info.m_state & wxLIST_STATE_FOCUSED)
1775 lvItem.state |= LVIS_FOCUSED;
1776 }
1777 if (info.m_stateMask & wxLIST_STATE_SELECTED)
1778 {
1779 lvItem.stateMask |= LVIS_SELECTED;
1780 if (info.m_state & wxLIST_STATE_SELECTED)
1781 lvItem.state |= LVIS_SELECTED;
1782 }
acb62b84 1783 }
acb62b84 1784
0b5efdc7 1785 if (info.m_mask & wxLIST_MASK_TEXT)
acb62b84 1786 {
edccf428 1787 lvItem.mask |= LVIF_TEXT;
0b5efdc7
VZ
1788 if ( ctrl->GetWindowStyleFlag() & wxLC_USER_TEXT )
1789 {
1790 lvItem.pszText = LPSTR_TEXTCALLBACK;
1791 }
1792 else
1793 {
edccf428 1794 lvItem.pszText = WXSTRINGCAST info.m_text;
0b5efdc7
VZ
1795 if ( lvItem.pszText )
1796 lvItem.cchTextMax = info.m_text.Length();
1797 else
1798 lvItem.cchTextMax = 0;
1799 }
acb62b84 1800 }
0b5efdc7 1801 if (info.m_mask & wxLIST_MASK_IMAGE)
edccf428 1802 lvItem.mask |= LVIF_IMAGE;
0b5efdc7 1803 if (info.m_mask & wxLIST_MASK_DATA)
edccf428 1804 lvItem.mask |= LVIF_PARAM;
2bda0e17
KB
1805}
1806
edccf428 1807// ----------------------------------------------------------------------------
2bda0e17 1808// List event
edccf428
VZ
1809// ----------------------------------------------------------------------------
1810
92976ab6 1811IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
2bda0e17 1812
fd3f686c 1813wxListEvent::wxListEvent(wxEventType commandType, int id)
edccf428 1814 : wxNotifyEvent(commandType, id)
2bda0e17 1815{
0b5efdc7
VZ
1816 m_code = 0;
1817 m_itemIndex = 0;
5d47c8a0 1818 m_oldItemIndex = 0;
0b5efdc7
VZ
1819 m_col = 0;
1820 m_cancelled = FALSE;
2bda0e17
KB
1821}
1822
edccf428 1823#endif // __WIN95__
2bda0e17 1824