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