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