]> git.saurik.com Git - wxWidgets.git/blame - src/msw/listctrl.cpp
compilation fix
[wxWidgets.git] / src / msw / listctrl.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
648bec3e 2// Name: src/msw/listctrl.cpp
2bda0e17
KB
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
98ec9dbe 32#if wxUSE_LISTCTRL && defined(__WIN95__)
9f303149 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"
2bda0e17 43#include "wx/listctrl.h"
68fdcf29 44#include "wx/dcclient.h"
2bda0e17
KB
45
46#include "wx/msw/private.h"
47
ae090fdb 48#if ((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__))
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
30a72e62
VZ
67#ifndef LVS_OWNERDATA
68 #define LVS_OWNERDATA 0x1000
69#endif
70
ed8a10f8
MB
71#ifndef LVM_FIRST
72 #define LVM_FIRST 0x1000
73#endif
74
75#ifndef HDM_FIRST
76 #define HDM_FIRST 0x1200
77#endif
78
82dfea77
VZ
79// mingw32/cygwin don't have declarations for comctl32.dll 4.70+ stuff
80#ifndef NM_CACHEHINT
81 typedef struct tagNMLVCACHEHINT
82 {
83 NMHDR hdr;
84 int iFrom;
85 int iTo;
86 } NMLVCACHEHINT;
87
88 #define NM_CACHEHINT NMLVCACHEHINT
89#endif
90
91#ifndef LVN_ODCACHEHINT
92 #define LVN_ODCACHEHINT (-113)
93#endif
94
0b52d3cf
VS
95#ifndef ListView_GetHeader
96 #define ListView_GetHeader(w) (HWND)SendMessage((w),LVM_GETHEADER,0,0)
97#endif
98
99#ifndef LVM_GETHEADER
100 #define LVM_GETHEADER (LVM_FIRST+31)
101#endif
102
103#ifndef Header_GetItemRect
104 #define Header_GetItemRect(w,i,r) \
105 (BOOL)SendMessage((w),HDM_GETITEMRECT,(WPARAM)(i),(LPARAM)(r))
106#endif
107
108#ifndef HDM_GETITEMRECT
109 #define HDM_GETITEMRECT (HDM_FIRST+7)
110#endif
111
244531bc
VS
112#ifndef LVCF_IMAGE
113 #define LVCF_IMAGE 0x0010
114#endif
115
116#ifndef LVCFMT_BITMAP_ON_RIGHT
117 #define LVCFMT_BITMAP_ON_RIGHT 0x1000
118#endif
119
edccf428
VZ
120// ----------------------------------------------------------------------------
121// private functions
122// ----------------------------------------------------------------------------
2bda0e17 123
8dff2b5c
VZ
124// convert our state and mask flags to LV_ITEM constants
125static void wxConvertToMSWFlags(long state, long mask, LV_ITEM& lvItem);
126
127// convert wxListItem to LV_ITEM
128static void wxConvertToMSWListItem(const wxListCtrl *ctrl,
129 const wxListItem& info, LV_ITEM& lvItem);
130
131// convert LV_ITEM to wxListItem
132static void wxConvertFromMSWListItem(HWND hwndListCtrl,
133 wxListItem& info,
134 /* const */ LV_ITEM& lvItem);
2bda0e17 135
6f806543
VZ
136// convert our wxListItem to LV_COLUMN
137static void wxConvertToMSWListCol(int col, const wxListItem& item,
138 LV_COLUMN& lvCol);
139
edccf428 140// ----------------------------------------------------------------------------
2e4df4bf 141// events
edccf428
VZ
142// ----------------------------------------------------------------------------
143
2e4df4bf
VZ
144DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG)
145DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG)
146DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT)
147DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT)
148DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM)
149DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS)
150DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO)
151DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO)
152DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED)
153DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED)
154DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN)
155DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM)
156DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK)
11358d39
VZ
157DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK)
158DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG)
159DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING)
160DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG)
2e4df4bf
VZ
161DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK)
162DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK)
163DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED)
0ddefeb0 164DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED)
614391dc 165DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT)
2e4df4bf 166
8f177c8e 167IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
bf9b6266 168IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl)
8f177c8e 169IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
2bda0e17 170
2d33aec9
VZ
171IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
172
2702ed5a
JS
173BEGIN_EVENT_TABLE(wxListCtrl, wxControl)
174 EVT_PAINT(wxListCtrl::OnPaint)
175END_EVENT_TABLE()
176
edccf428
VZ
177// ============================================================================
178// implementation
179// ============================================================================
180
181// ----------------------------------------------------------------------------
182// wxListCtrl construction
183// ----------------------------------------------------------------------------
184
bdc72a22 185void wxListCtrl::Init()
2bda0e17 186{
0b5efdc7
VZ
187 m_imageListNormal = NULL;
188 m_imageListSmall = NULL;
189 m_imageListState = NULL;
2e12c11a 190 m_ownsImageListNormal = m_ownsImageListSmall = m_ownsImageListState = FALSE;
0b5efdc7 191 m_baseStyle = 0;
2bda0e17 192 m_colCount = 0;
bbcdf8bc 193 m_textCtrl = NULL;
bdc72a22 194 m_hasAnyAttr = FALSE;
2bda0e17
KB
195}
196
0b5efdc7
VZ
197bool wxListCtrl::Create(wxWindow *parent,
198 wxWindowID id,
199 const wxPoint& pos,
200 const wxSize& size,
201 long style,
202 const wxValidator& validator,
203 const wxString& name)
2bda0e17 204{
11b6a93b 205#if wxUSE_VALIDATORS
0b5efdc7 206 SetValidator(validator);
11b6a93b
VZ
207#endif // wxUSE_VALIDATORS
208
0b5efdc7 209 SetName(name);
2bda0e17 210
0b5efdc7
VZ
211 int x = pos.x;
212 int y = pos.y;
213 int width = size.x;
214 int height = size.y;
2bda0e17 215
0b5efdc7 216 m_windowStyle = style;
2bda0e17 217
0b5efdc7 218 SetParent(parent);
2bda0e17 219
0b5efdc7
VZ
220 if (width <= 0)
221 width = 100;
222 if (height <= 0)
223 height = 30;
224 if (x < 0)
225 x = 0;
226 if (y < 0)
227 y = 0;
2bda0e17 228
0b5efdc7 229 m_windowId = (id == -1) ? NewControlId() : id;
2bda0e17 230
edccf428
VZ
231 DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP |
232 LVS_SHAREIMAGELISTS | LVS_SHOWSELALWAYS;
b0766406
JS
233
234 if ( m_windowStyle & wxCLIP_SIBLINGS )
235 wstyle |= WS_CLIPSIBLINGS;
236
edccf428
VZ
237 if ( wxStyleHasBorder(m_windowStyle) )
238 wstyle |= WS_BORDER;
239 m_baseStyle = wstyle;
240
241 if ( !DoCreateControl(x, y, width, height) )
242 return FALSE;
243
244 if (parent)
245 parent->AddChild(this);
246
247 return TRUE;
248}
249
250bool wxListCtrl::DoCreateControl(int x, int y, int w, int h)
251{
252 DWORD wstyle = m_baseStyle;
2bda0e17 253
0b5efdc7 254 bool want3D;
edccf428 255 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D);
2bda0e17 256
0b5efdc7
VZ
257 // Even with extended styles, need to combine with WS_BORDER
258 // for them to look right.
edccf428 259 if ( want3D )
0b5efdc7 260 wstyle |= WS_BORDER;
2bda0e17 261
0b5efdc7
VZ
262 long oldStyle = 0; // Dummy
263 wstyle |= ConvertToMSWStyle(oldStyle, m_windowStyle);
2bda0e17 264
0b5efdc7
VZ
265 // Create the ListView control.
266 m_hWnd = (WXHWND)CreateWindowEx(exStyle,
267 WC_LISTVIEW,
223d09f6 268 wxT(""),
0b5efdc7 269 wstyle,
edccf428
VZ
270 x, y, w, h,
271 GetWinHwnd(GetParent()),
0b5efdc7
VZ
272 (HMENU)m_windowId,
273 wxGetInstance(),
274 NULL);
f8352807 275
edccf428
VZ
276 if ( !m_hWnd )
277 {
f6bcfd97 278 wxLogError(_("Can't create list control window, check that comctl32.dll is installed."));
0b5efdc7
VZ
279
280 return FALSE;
281 }
282
283 // for comctl32.dll v 4.70+ we want to have this attribute because it's
284 // prettier (and also because wxGTK does it like this)
225fe9d6 285 if ( (wstyle & LVS_REPORT) && wxTheApp->GetComCtl32Version() >= 470 )
0b5efdc7 286 {
225fe9d6
VZ
287 ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE,
288 0, LVS_EX_FULLROWSELECT);
0b5efdc7 289 }
f8352807 290
a756f210 291 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
edccf428 292 SetForegroundColour(GetParent()->GetForegroundColour());
2bda0e17 293
edccf428 294 SubclassWin(m_hWnd);
2bda0e17 295
0b5efdc7 296 return TRUE;
2bda0e17
KB
297}
298
edccf428
VZ
299void wxListCtrl::UpdateStyle()
300{
301 if ( GetHWND() )
302 {
303 // The new window view style
304 long dummy;
305 DWORD dwStyleNew = ConvertToMSWStyle(dummy, m_windowStyle);
306 dwStyleNew |= m_baseStyle;
307
910484a6 308 // Get the current window style.
edccf428
VZ
309 DWORD dwStyleOld = ::GetWindowLong(GetHwnd(), GWL_STYLE);
310
910484a6 311 // Only set the window style if the view bits have changed.
edccf428
VZ
312 if ( dwStyleOld != dwStyleNew )
313 {
314 ::SetWindowLong(GetHwnd(), GWL_STYLE, dwStyleNew);
315 }
316 }
317}
318
91b4c08d 319void wxListCtrl::FreeAllAttrs(bool dontRecreate)
2bda0e17 320{
d62228a6
VZ
321 if ( m_hasAnyAttr )
322 {
323 for ( wxNode *node = m_attrs.Next(); node; node = m_attrs.Next() )
324 {
325 delete (wxListItemAttr *)node->Data();
326 }
6932a32c
VZ
327
328 m_attrs.Destroy();
91b4c08d
VZ
329 if ( !dontRecreate )
330 {
331 m_attrs.Create(wxKEY_INTEGER, 1000); // just as def ctor
332 }
6932a32c
VZ
333
334 m_hasAnyAttr = FALSE;
d62228a6 335 }
6932a32c 336}
d62228a6 337
6932a32c
VZ
338wxListCtrl::~wxListCtrl()
339{
91b4c08d
VZ
340 FreeAllAttrs(TRUE /* no need to recreate hash any more */);
341
d62228a6 342 if ( m_textCtrl )
bbcdf8bc 343 {
0b5efdc7 344 m_textCtrl->SetHWND(0);
7bf1474a 345 m_textCtrl->UnsubclassWin();
0b5efdc7
VZ
346 delete m_textCtrl;
347 m_textCtrl = NULL;
bbcdf8bc 348 }
33ac7e6f 349
2e12c11a
VS
350 if (m_ownsImageListNormal) delete m_imageListNormal;
351 if (m_ownsImageListSmall) delete m_imageListSmall;
352 if (m_ownsImageListState) delete m_imageListState;
2bda0e17
KB
353}
354
edccf428
VZ
355// ----------------------------------------------------------------------------
356// set/get/change style
357// ----------------------------------------------------------------------------
358
2bda0e17 359// Add or remove a single window style
debe6624 360void wxListCtrl::SetSingleStyle(long style, bool add)
2bda0e17 361{
0b5efdc7 362 long flag = GetWindowStyleFlag();
2bda0e17 363
0b5efdc7 364 // Get rid of conflicting styles
acb62b84
VZ
365 if ( add )
366 {
0b5efdc7 367 if ( style & wxLC_MASK_TYPE)
edccf428 368 flag = flag & ~wxLC_MASK_TYPE;
0b5efdc7 369 if ( style & wxLC_MASK_ALIGN )
edccf428 370 flag = flag & ~wxLC_MASK_ALIGN;
0b5efdc7 371 if ( style & wxLC_MASK_SORT )
edccf428 372 flag = flag & ~wxLC_MASK_SORT;
acb62b84 373 }
2bda0e17 374
0b5efdc7
VZ
375 if ( flag & style )
376 {
377 if ( !add )
378 flag -= style;
379 }
380 else
381 {
382 if ( add )
383 {
384 flag |= style;
385 }
386 }
387
388 m_windowStyle = flag;
2bda0e17 389
edccf428 390 UpdateStyle();
2bda0e17
KB
391}
392
393// Set the whole window style
debe6624 394void wxListCtrl::SetWindowStyleFlag(long flag)
2bda0e17 395{
0b5efdc7 396 m_windowStyle = flag;
2bda0e17 397
edccf428 398 UpdateStyle();
2bda0e17
KB
399}
400
0b5efdc7
VZ
401// Can be just a single style, or a bitlist
402long wxListCtrl::ConvertToMSWStyle(long& oldStyle, long style) const
2bda0e17 403{
0b5efdc7
VZ
404 long wstyle = 0;
405 if ( style & wxLC_ICON )
406 {
407 if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON )
408 oldStyle -= LVS_SMALLICON;
409 if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT )
410 oldStyle -= LVS_REPORT;
411 if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST )
412 oldStyle -= LVS_LIST;
413 wstyle |= LVS_ICON;
414 }
415
416 if ( style & wxLC_SMALL_ICON )
417 {
418 if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON )
419 oldStyle -= LVS_ICON;
420 if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT )
421 oldStyle -= LVS_REPORT;
422 if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST )
423 oldStyle -= LVS_LIST;
424 wstyle |= LVS_SMALLICON;
425 }
426
427 if ( style & wxLC_LIST )
428 {
429 if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON )
430 oldStyle -= LVS_ICON;
431 if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT )
432 oldStyle -= LVS_REPORT;
433 if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON )
434 oldStyle -= LVS_SMALLICON;
435 wstyle |= LVS_LIST;
436 }
2bda0e17 437
0b5efdc7
VZ
438 if ( style & wxLC_REPORT )
439 {
440 if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON )
441 oldStyle -= LVS_ICON;
442 if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST )
443 oldStyle -= LVS_LIST;
444 if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON )
445 oldStyle -= LVS_SMALLICON;
446
447 wstyle |= LVS_REPORT;
448 }
2bda0e17 449
0b5efdc7
VZ
450 if ( style & wxLC_ALIGN_LEFT )
451 {
452 if ( oldStyle & LVS_ALIGNTOP )
453 oldStyle -= LVS_ALIGNTOP;
454 wstyle |= LVS_ALIGNLEFT;
455 }
2bda0e17 456
0b5efdc7
VZ
457 if ( style & wxLC_ALIGN_TOP )
458 {
459 if ( oldStyle & LVS_ALIGNLEFT )
460 oldStyle -= LVS_ALIGNLEFT;
461 wstyle |= LVS_ALIGNTOP;
462 }
2bda0e17 463
0b5efdc7
VZ
464 if ( style & wxLC_AUTOARRANGE )
465 wstyle |= LVS_AUTOARRANGE;
2bda0e17 466
0b5efdc7
VZ
467 if ( style & wxLC_NO_SORT_HEADER )
468 wstyle |= LVS_NOSORTHEADER;
2bda0e17 469
0b5efdc7
VZ
470 if ( style & wxLC_NO_HEADER )
471 wstyle |= LVS_NOCOLUMNHEADER;
472
473 if ( style & wxLC_EDIT_LABELS )
474 wstyle |= LVS_EDITLABELS;
475
476 if ( style & wxLC_SINGLE_SEL )
477 wstyle |= LVS_SINGLESEL;
478
479 if ( style & wxLC_SORT_ASCENDING )
480 {
481 if ( oldStyle & LVS_SORTDESCENDING )
482 oldStyle -= LVS_SORTDESCENDING;
483 wstyle |= LVS_SORTASCENDING;
484 }
485
486 if ( style & wxLC_SORT_DESCENDING )
487 {
488 if ( oldStyle & LVS_SORTASCENDING )
489 oldStyle -= LVS_SORTASCENDING;
490 wstyle |= LVS_SORTDESCENDING;
491 }
492
bf9b6266 493#if !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
98ec9dbe
VZ
494 if ( style & wxLC_VIRTUAL )
495 {
30a72e62
VZ
496 int ver = wxTheApp->GetComCtl32Version();
497 if ( ver < 470 )
498 {
bf9b6266 499 wxLogWarning(_("Please install a newer version of comctl32.dll\n(at least version 4.70 is required but you have %d.%02d)\nor this program won't operate correctly."),
30a72e62
VZ
500 ver / 100, ver % 100);
501 }
502
98ec9dbe
VZ
503 wstyle |= LVS_OWNERDATA;
504 }
bf9b6266 505#endif
98ec9dbe 506
0b5efdc7 507 return wstyle;
2bda0e17
KB
508}
509
edccf428
VZ
510// ----------------------------------------------------------------------------
511// accessors
512// ----------------------------------------------------------------------------
513
91b4c08d
VZ
514// Sets the foreground, i.e. text, colour
515bool wxListCtrl::SetForegroundColour(const wxColour& col)
516{
517 if ( !wxWindow::SetForegroundColour(col) )
518 return FALSE;
519
520 ListView_SetTextColor(GetHwnd(), wxColourToRGB(col));
521
522 return TRUE;
523}
524
525// Sets the background colour
cc2b7472 526bool wxListCtrl::SetBackgroundColour(const wxColour& col)
2bda0e17 527{
cc2b7472
VZ
528 if ( !wxWindow::SetBackgroundColour(col) )
529 return FALSE;
2bda0e17 530
91b4c08d
VZ
531 // we set the same colour for both the "empty" background and the items
532 // background
533 COLORREF color = wxColourToRGB(col);
534 ListView_SetBkColor(GetHwnd(), color);
535 ListView_SetTextBkColor(GetHwnd(), color);
cc2b7472
VZ
536
537 return TRUE;
2bda0e17
KB
538}
539
540// Gets information about this column
debe6624 541bool wxListCtrl::GetColumn(int col, wxListItem& item) const
2bda0e17 542{
0b5efdc7 543 LV_COLUMN lvCol;
6f806543 544 wxZeroMemory(lvCol);
0b5efdc7
VZ
545
546 if ( item.m_mask & wxLIST_MASK_TEXT )
547 {
548 lvCol.mask |= LVCF_TEXT;
837e5743 549 lvCol.pszText = new wxChar[513];
0b5efdc7
VZ
550 lvCol.cchTextMax = 512;
551 }
552
6f806543 553 bool success = ListView_GetColumn(GetHwnd(), col, & lvCol) != 0;
0b5efdc7
VZ
554
555 // item.m_subItem = lvCol.iSubItem;
556 item.m_width = lvCol.cx;
557
558 if ( (item.m_mask & wxLIST_MASK_TEXT) && lvCol.pszText )
559 {
560 item.m_text = lvCol.pszText;
561 delete[] lvCol.pszText;
562 }
563
564 if ( item.m_mask & wxLIST_MASK_FORMAT )
565 {
566 if (lvCol.fmt == LVCFMT_LEFT)
567 item.m_format = wxLIST_FORMAT_LEFT;
568 else if (lvCol.fmt == LVCFMT_RIGHT)
569 item.m_format = wxLIST_FORMAT_RIGHT;
570 else if (lvCol.fmt == LVCFMT_CENTER)
571 item.m_format = wxLIST_FORMAT_CENTRE;
2bda0e17
KB
572 }
573
0b5efdc7 574 return success;
2bda0e17
KB
575}
576
577// Sets information about this column
debe6624 578bool wxListCtrl::SetColumn(int col, wxListItem& item)
2bda0e17 579{
0b5efdc7 580 LV_COLUMN lvCol;
6f806543 581 wxConvertToMSWListCol(col, item, lvCol);
0b5efdc7 582
6f806543 583 return ListView_SetColumn(GetHwnd(), col, &lvCol) != 0;
2bda0e17
KB
584}
585
586// Gets the column width
debe6624 587int wxListCtrl::GetColumnWidth(int col) const
2bda0e17 588{
edccf428 589 return ListView_GetColumnWidth(GetHwnd(), col);
2bda0e17
KB
590}
591
592// Sets the column width
debe6624 593bool wxListCtrl::SetColumnWidth(int col, int width)
2bda0e17 594{
0b5efdc7
VZ
595 int col2 = col;
596 if ( m_windowStyle & wxLC_LIST )
597 col2 = -1;
2bda0e17 598
0b5efdc7
VZ
599 int width2 = width;
600 if ( width2 == wxLIST_AUTOSIZE)
601 width2 = LVSCW_AUTOSIZE;
602 else if ( width2 == wxLIST_AUTOSIZE_USEHEADER)
603 width2 = LVSCW_AUTOSIZE_USEHEADER;
2bda0e17 604
6f806543 605 return ListView_SetColumnWidth(GetHwnd(), col2, width2) != 0;
2bda0e17
KB
606}
607
608// Gets the number of items that can fit vertically in the
609// visible area of the list control (list or report view)
610// or the total number of items in the list control (icon
611// or small icon view)
c42404a5 612int wxListCtrl::GetCountPerPage() const
2bda0e17 613{
edccf428 614 return ListView_GetCountPerPage(GetHwnd());
2bda0e17
KB
615}
616
617// Gets the edit control for editing labels.
c42404a5 618wxTextCtrl* wxListCtrl::GetEditControl() const
2bda0e17 619{
bbcdf8bc 620 return m_textCtrl;
2bda0e17
KB
621}
622
623// Gets information about the item
624bool wxListCtrl::GetItem(wxListItem& info) const
625{
0b5efdc7 626 LV_ITEM lvItem;
11c7d5b6 627 wxZeroMemory(lvItem);
2bda0e17 628
0b5efdc7 629 lvItem.iItem = info.m_itemId;
fc5a93cd 630 lvItem.iSubItem = info.m_col;
0b5efdc7
VZ
631
632 if ( info.m_mask & wxLIST_MASK_TEXT )
633 {
634 lvItem.mask |= LVIF_TEXT;
837e5743 635 lvItem.pszText = new wxChar[513];
0b5efdc7
VZ
636 lvItem.cchTextMax = 512;
637 }
638 else
639 {
640 lvItem.pszText = NULL;
641 }
642
643 if (info.m_mask & wxLIST_MASK_DATA)
edccf428 644 lvItem.mask |= LVIF_PARAM;
0b5efdc7 645
2189c644
JS
646 if (info.m_mask & wxLIST_MASK_IMAGE)
647 lvItem.mask |= LVIF_IMAGE;
648
0b5efdc7
VZ
649 if ( info.m_mask & wxLIST_MASK_STATE )
650 {
651 lvItem.mask |= LVIF_STATE;
652 // the other bits are hardly interesting anyhow
653 lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
654 }
655
656 bool success = ListView_GetItem((HWND)GetHWND(), &lvItem) != 0;
657 if ( !success )
658 {
659 wxLogError(_("Couldn't retrieve information about list control item %d."),
660 lvItem.iItem);
661 }
662 else
663 {
dccde0c0
VZ
664 // give NULL as hwnd as we already have everything we need
665 wxConvertFromMSWListItem(NULL, info, lvItem);
0b5efdc7
VZ
666 }
667
668 if (lvItem.pszText)
669 delete[] lvItem.pszText;
670
671 return success;
2bda0e17
KB
672}
673
674// Sets information about the item
675bool wxListCtrl::SetItem(wxListItem& info)
676{
0b5efdc7 677 LV_ITEM item;
2bda0e17 678 wxConvertToMSWListItem(this, info, item);
bdc72a22 679
2d33aec9
VZ
680 // we could be changing only the attribute in which case we don't need to
681 // call ListView_SetItem() at all
682 if ( item.mask )
bdc72a22 683 {
2d33aec9
VZ
684 item.cchTextMax = 0;
685 if ( !ListView_SetItem(GetHwnd(), &item) )
686 {
687 wxLogDebug(_T("ListView_SetItem() failed"));
2702ed5a 688
2d33aec9
VZ
689 return FALSE;
690 }
233d0295 691 }
2702ed5a 692
233d0295
VZ
693 // we need to update the item immediately to show the new image
694 bool updateNow = (info.m_mask & wxLIST_MASK_IMAGE) != 0;
2702ed5a 695
233d0295
VZ
696 // check whether it has any custom attributes
697 if ( info.HasAttributes() )
698 {
699 wxListItemAttr *attr = (wxListItemAttr *)m_attrs.Get(item.iItem);
2702ed5a 700
233d0295
VZ
701 if ( attr == NULL )
702 m_attrs.Put(item.iItem, (wxObject *)new wxListItemAttr(*info.GetAttributes()));
703 else
704 *attr = *info.GetAttributes();
bdc72a22
VZ
705
706 m_hasAnyAttr = TRUE;
233d0295
VZ
707
708 // if the colour has changed, we must redraw the item
709 updateNow = TRUE;
bdc72a22 710 }
bdc72a22 711
233d0295 712 if ( updateNow )
7cc98b3e 713 {
233d0295 714 // we need this to make the change visible right now
2d33aec9 715 RefreshItem(item.iItem);
7cc98b3e
VZ
716 }
717
233d0295 718 return TRUE;
2bda0e17
KB
719}
720
debe6624 721long wxListCtrl::SetItem(long index, int col, const wxString& label, int imageId)
2bda0e17 722{
0b5efdc7
VZ
723 wxListItem info;
724 info.m_text = label;
725 info.m_mask = wxLIST_MASK_TEXT;
726 info.m_itemId = index;
727 info.m_col = col;
728 if ( imageId > -1 )
729 {
730 info.m_image = imageId;
731 info.m_mask |= wxLIST_MASK_IMAGE;
732 }
733 return SetItem(info);
2bda0e17
KB
734}
735
736
737// Gets the item state
debe6624 738int wxListCtrl::GetItemState(long item, long stateMask) const
2bda0e17 739{
0b5efdc7 740 wxListItem info;
2bda0e17 741
edccf428 742 info.m_mask = wxLIST_MASK_STATE;
0b5efdc7
VZ
743 info.m_stateMask = stateMask;
744 info.m_itemId = item;
2bda0e17 745
0b5efdc7
VZ
746 if (!GetItem(info))
747 return 0;
2bda0e17 748
0b5efdc7 749 return info.m_state;
2bda0e17
KB
750}
751
752// Sets the item state
debe6624 753bool wxListCtrl::SetItemState(long item, long state, long stateMask)
2bda0e17 754{
8dff2b5c
VZ
755 // NB: don't use SetItem() here as it doesn't work with the virtual list
756 // controls
757 LV_ITEM lvItem;
758 wxZeroMemory(lvItem);
2bda0e17 759
8dff2b5c 760 wxConvertToMSWFlags(state, stateMask, lvItem);
2bda0e17 761
2d33aec9 762 // for the virtual list controls we need to refresh the previously focused
ad9f477d
VZ
763 // item manually when changing focus without changing selection
764 // programmatically because otherwise it keeps its focus rectangle until
765 // next repaint (yet another comctl32 bug)
2d33aec9
VZ
766 long focusOld;
767 if ( IsVirtual() &&
768 (stateMask & wxLIST_STATE_FOCUSED) &&
769 (state & wxLIST_STATE_FOCUSED) )
770 {
771 focusOld = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
772 }
773 else
774 {
775 focusOld = -1;
776 }
777
8dff2b5c
VZ
778 if ( !::SendMessage(GetHwnd(), LVM_SETITEMSTATE,
779 (WPARAM)item, (LPARAM)&lvItem) )
780 {
781 wxLogLastError(_T("ListView_SetItemState"));
782
783 return FALSE;
784 }
785
2d33aec9
VZ
786 if ( focusOld != -1 )
787 {
ad9f477d
VZ
788 // no need to refresh the item if it was previously selected, it would
789 // only result in annoying flicker
790 if ( !(GetItemState(focusOld,
791 wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED) )
792 {
793 RefreshItem(focusOld);
794 }
2d33aec9
VZ
795 }
796
8dff2b5c 797 return TRUE;
2bda0e17
KB
798}
799
800// Sets the item image
33ac7e6f 801bool wxListCtrl::SetItemImage(long item, int image, int WXUNUSED(selImage))
2bda0e17 802{
0b5efdc7 803 wxListItem info;
2bda0e17 804
edccf428 805 info.m_mask = wxLIST_MASK_IMAGE;
0b5efdc7
VZ
806 info.m_image = image;
807 info.m_itemId = item;
2bda0e17 808
0b5efdc7 809 return SetItem(info);
2bda0e17
KB
810}
811
812// Gets the item text
debe6624 813wxString wxListCtrl::GetItemText(long item) const
2bda0e17 814{
0b5efdc7 815 wxListItem info;
2bda0e17 816
edccf428 817 info.m_mask = wxLIST_MASK_TEXT;
0b5efdc7 818 info.m_itemId = item;
2bda0e17 819
0b5efdc7
VZ
820 if (!GetItem(info))
821 return wxString("");
822 return info.m_text;
2bda0e17
KB
823}
824
825// Sets the item text
debe6624 826void wxListCtrl::SetItemText(long item, const wxString& str)
2bda0e17 827{
0b5efdc7 828 wxListItem info;
2bda0e17 829
edccf428 830 info.m_mask = wxLIST_MASK_TEXT;
0b5efdc7
VZ
831 info.m_itemId = item;
832 info.m_text = str;
2bda0e17 833
0b5efdc7 834 SetItem(info);
2bda0e17
KB
835}
836
837// Gets the item data
debe6624 838long wxListCtrl::GetItemData(long item) const
2bda0e17 839{
0b5efdc7 840 wxListItem info;
2bda0e17 841
edccf428 842 info.m_mask = wxLIST_MASK_DATA;
0b5efdc7 843 info.m_itemId = item;
2bda0e17 844
0b5efdc7
VZ
845 if (!GetItem(info))
846 return 0;
847 return info.m_data;
2bda0e17
KB
848}
849
850// Sets the item data
debe6624 851bool wxListCtrl::SetItemData(long item, long data)
2bda0e17 852{
0b5efdc7 853 wxListItem info;
2bda0e17 854
edccf428 855 info.m_mask = wxLIST_MASK_DATA;
0b5efdc7
VZ
856 info.m_itemId = item;
857 info.m_data = data;
2bda0e17 858
0b5efdc7 859 return SetItem(info);
2bda0e17
KB
860}
861
862// Gets the item rectangle
16e93305 863bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const
2bda0e17 864{
2d33aec9 865 RECT rectWin;
2bda0e17 866
2d33aec9 867 int codeWin;
0b5efdc7 868 if ( code == wxLIST_RECT_BOUNDS )
2d33aec9 869 codeWin = LVIR_BOUNDS;
0b5efdc7 870 else if ( code == wxLIST_RECT_ICON )
2d33aec9 871 codeWin = LVIR_ICON;
0b5efdc7 872 else if ( code == wxLIST_RECT_LABEL )
2d33aec9
VZ
873 codeWin = LVIR_LABEL;
874 else
875 {
876 wxFAIL_MSG( _T("incorrect code in GetItemRect()") );
877
878 codeWin = LVIR_BOUNDS;
879 }
2bda0e17 880
5ea105e0 881#ifdef __WXWINE__
2d33aec9 882 bool success = ListView_GetItemRect(GetHwnd(), (int) item, &rectWin ) != 0;
5ea105e0 883#else
2d33aec9 884 bool success = ListView_GetItemRect(GetHwnd(), (int) item, &rectWin, codeWin) != 0;
5ea105e0 885#endif
2bda0e17 886
2d33aec9
VZ
887 rect.x = rectWin.left;
888 rect.y = rectWin.top;
889 rect.width = rectWin.right - rectWin.left;
890 rect.height = rectWin.bottom - rectWin.top;
891
0b5efdc7 892 return success;
2bda0e17
KB
893}
894
895// Gets the item position
debe6624 896bool wxListCtrl::GetItemPosition(long item, wxPoint& pos) const
2bda0e17 897{
0b5efdc7 898 POINT pt;
2bda0e17 899
edccf428 900 bool success = (ListView_GetItemPosition(GetHwnd(), (int) item, &pt) != 0);
2bda0e17 901
0b5efdc7
VZ
902 pos.x = pt.x; pos.y = pt.y;
903 return success;
2bda0e17
KB
904}
905
906// Sets the item position.
debe6624 907bool wxListCtrl::SetItemPosition(long item, const wxPoint& pos)
2bda0e17 908{
edccf428 909 return (ListView_SetItemPosition(GetHwnd(), (int) item, pos.x, pos.y) != 0);
2bda0e17
KB
910}
911
912// Gets the number of items in the list control
c42404a5 913int wxListCtrl::GetItemCount() const
2bda0e17 914{
edccf428 915 return ListView_GetItemCount(GetHwnd());
2bda0e17
KB
916}
917
918// Retrieves the spacing between icons in pixels.
919// If small is TRUE, gets the spacing for the small icon
920// view, otherwise the large icon view.
921int wxListCtrl::GetItemSpacing(bool isSmall) const
922{
edccf428 923 return ListView_GetItemSpacing(GetHwnd(), (BOOL) isSmall);
2bda0e17
KB
924}
925
926// Gets the number of selected items in the list control
c42404a5 927int wxListCtrl::GetSelectedItemCount() const
2bda0e17 928{
edccf428 929 return ListView_GetSelectedCount(GetHwnd());
2bda0e17
KB
930}
931
932// Gets the text colour of the listview
c42404a5 933wxColour wxListCtrl::GetTextColour() const
2bda0e17 934{
edccf428 935 COLORREF ref = ListView_GetTextColor(GetHwnd());
0b5efdc7
VZ
936 wxColour col(GetRValue(ref), GetGValue(ref), GetBValue(ref));
937 return col;
2bda0e17
KB
938}
939
940// Sets the text colour of the listview
941void wxListCtrl::SetTextColour(const wxColour& col)
942{
910484a6 943 ListView_SetTextColor(GetHwnd(), PALETTERGB(col.Red(), col.Green(), col.Blue()));
2bda0e17
KB
944}
945
946// Gets the index of the topmost visible item when in
947// list or report view
c42404a5 948long wxListCtrl::GetTopItem() const
2bda0e17 949{
edccf428 950 return (long) ListView_GetTopIndex(GetHwnd());
2bda0e17
KB
951}
952
953// Searches for an item, starting from 'item'.
954// 'geometry' is one of
955// wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
956// 'state' is a state bit flag, one or more of
957// wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
958// item can be -1 to find the first item that matches the
959// specified flags.
960// Returns the item or -1 if unsuccessful.
debe6624 961long wxListCtrl::GetNextItem(long item, int geom, int state) const
2bda0e17 962{
0b5efdc7 963 long flags = 0;
2bda0e17 964
0b5efdc7
VZ
965 if ( geom == wxLIST_NEXT_ABOVE )
966 flags |= LVNI_ABOVE;
967 if ( geom == wxLIST_NEXT_ALL )
968 flags |= LVNI_ALL;
969 if ( geom == wxLIST_NEXT_BELOW )
970 flags |= LVNI_BELOW;
971 if ( geom == wxLIST_NEXT_LEFT )
972 flags |= LVNI_TOLEFT;
973 if ( geom == wxLIST_NEXT_RIGHT )
974 flags |= LVNI_TORIGHT;
2bda0e17 975
0b5efdc7
VZ
976 if ( state & wxLIST_STATE_CUT )
977 flags |= LVNI_CUT;
978 if ( state & wxLIST_STATE_DROPHILITED )
979 flags |= LVNI_DROPHILITED;
980 if ( state & wxLIST_STATE_FOCUSED )
981 flags |= LVNI_FOCUSED;
982 if ( state & wxLIST_STATE_SELECTED )
983 flags |= LVNI_SELECTED;
2bda0e17 984
edccf428 985 return (long) ListView_GetNextItem(GetHwnd(), item, flags);
2bda0e17
KB
986}
987
988
debe6624 989wxImageList *wxListCtrl::GetImageList(int which) const
2bda0e17 990{
0b5efdc7 991 if ( which == wxIMAGE_LIST_NORMAL )
2bda0e17 992 {
0b5efdc7
VZ
993 return m_imageListNormal;
994 }
995 else if ( which == wxIMAGE_LIST_SMALL )
2bda0e17 996 {
0b5efdc7
VZ
997 return m_imageListSmall;
998 }
999 else if ( which == wxIMAGE_LIST_STATE )
2bda0e17 1000 {
0b5efdc7
VZ
1001 return m_imageListState;
1002 }
1003 return NULL;
2bda0e17
KB
1004}
1005
debe6624 1006void wxListCtrl::SetImageList(wxImageList *imageList, int which)
2bda0e17 1007{
0b5efdc7
VZ
1008 int flags = 0;
1009 if ( which == wxIMAGE_LIST_NORMAL )
2bda0e17 1010 {
0b5efdc7 1011 flags = LVSIL_NORMAL;
2e12c11a 1012 if (m_ownsImageListNormal) delete m_imageListNormal;
0b5efdc7 1013 m_imageListNormal = imageList;
2e12c11a 1014 m_ownsImageListNormal = FALSE;
0b5efdc7
VZ
1015 }
1016 else if ( which == wxIMAGE_LIST_SMALL )
2bda0e17 1017 {
0b5efdc7 1018 flags = LVSIL_SMALL;
2e12c11a 1019 if (m_ownsImageListSmall) delete m_imageListSmall;
0b5efdc7 1020 m_imageListSmall = imageList;
2e12c11a 1021 m_ownsImageListSmall = FALSE;
0b5efdc7
VZ
1022 }
1023 else if ( which == wxIMAGE_LIST_STATE )
2bda0e17 1024 {
0b5efdc7 1025 flags = LVSIL_STATE;
2e12c11a 1026 if (m_ownsImageListState) delete m_imageListState;
0b5efdc7 1027 m_imageListState = imageList;
2e12c11a 1028 m_ownsImageListState = FALSE;
0b5efdc7 1029 }
edccf428 1030 ListView_SetImageList(GetHwnd(), (HIMAGELIST) imageList ? imageList->GetHIMAGELIST() : 0, flags);
2bda0e17
KB
1031}
1032
2e12c11a
VS
1033void wxListCtrl::AssignImageList(wxImageList *imageList, int which)
1034{
1035 SetImageList(imageList, which);
1036 if ( which == wxIMAGE_LIST_NORMAL )
1037 m_ownsImageListNormal = TRUE;
1038 else if ( which == wxIMAGE_LIST_SMALL )
1039 m_ownsImageListSmall = TRUE;
1040 else if ( which == wxIMAGE_LIST_STATE )
1041 m_ownsImageListState = TRUE;
1042}
1043
edccf428 1044// ----------------------------------------------------------------------------
2bda0e17 1045// Operations
edccf428 1046// ----------------------------------------------------------------------------
2bda0e17
KB
1047
1048// Arranges the items
debe6624 1049bool wxListCtrl::Arrange(int flag)
2bda0e17 1050{
0b5efdc7
VZ
1051 UINT code = 0;
1052 if ( flag == wxLIST_ALIGN_LEFT )
1053 code = LVA_ALIGNLEFT;
1054 else if ( flag == wxLIST_ALIGN_TOP )
1055 code = LVA_ALIGNTOP;
1056 else if ( flag == wxLIST_ALIGN_DEFAULT )
1057 code = LVA_DEFAULT;
1058 else if ( flag == wxLIST_ALIGN_SNAP_TO_GRID )
1059 code = LVA_SNAPTOGRID;
2bda0e17 1060
edccf428 1061 return (ListView_Arrange(GetHwnd(), code) != 0);
2bda0e17
KB
1062}
1063
1064// Deletes an item
debe6624 1065bool wxListCtrl::DeleteItem(long item)
2bda0e17 1066{
2e9f62da
VZ
1067 if ( !ListView_DeleteItem(GetHwnd(), (int) item) )
1068 {
1069 wxLogLastError(_T("ListView_DeleteItem"));
1070 return FALSE;
1071 }
1072
1073 // the virtual list control doesn't refresh itself correctly, help it
1074 if ( IsVirtual() )
1075 {
1076 // we need to refresh all the lines below the one which was deleted
1077 wxRect rectItem;
1078 if ( item > 0 && GetItemCount() )
1079 {
1080 GetItemRect(item - 1, rectItem);
1081 }
1082 else
1083 {
1084 rectItem.y =
1085 rectItem.height = 0;
1086 }
1087
1088 wxRect rectWin = GetRect();
1089 rectWin.height = rectWin.GetBottom() - rectItem.GetBottom();
1090 rectWin.y = rectItem.GetBottom();
1091
1092 RefreshRect(rectWin);
1093 }
1094
1095 return TRUE;
2bda0e17
KB
1096}
1097
1098// Deletes all items
0b5efdc7 1099bool wxListCtrl::DeleteAllItems()
2bda0e17 1100{
2e9f62da 1101 return ListView_DeleteAllItems(GetHwnd()) != 0;
2bda0e17
KB
1102}
1103
1104// Deletes all items
0b5efdc7 1105bool wxListCtrl::DeleteAllColumns()
2bda0e17 1106{
edccf428 1107 while ( m_colCount > 0 )
2bda0e17 1108 {
edccf428
VZ
1109 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
1110 {
f6bcfd97 1111 wxLogLastError(wxT("ListView_DeleteColumn"));
edccf428
VZ
1112
1113 return FALSE;
1114 }
1115
1116 m_colCount--;
2bda0e17 1117 }
edccf428 1118
223d09f6 1119 wxASSERT_MSG( m_colCount == 0, wxT("no columns should be left") );
edccf428
VZ
1120
1121 return TRUE;
2bda0e17
KB
1122}
1123
1124// Deletes a column
debe6624 1125bool wxListCtrl::DeleteColumn(int col)
2bda0e17 1126{
edccf428 1127 bool success = (ListView_DeleteColumn(GetHwnd(), col) != 0);
2bda0e17
KB
1128
1129 if ( success && (m_colCount > 0) )
1130 m_colCount --;
1131 return success;
1132}
1133
1134// Clears items, and columns if there are any.
0b5efdc7 1135void wxListCtrl::ClearAll()
2bda0e17
KB
1136{
1137 DeleteAllItems();
1138 if ( m_colCount > 0 )
1139 DeleteAllColumns();
1140}
1141
bbcdf8bc
JS
1142wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass)
1143{
1144 wxASSERT( (textControlClass->IsKindOf(CLASSINFO(wxTextCtrl))) );
1145
d699f48b 1146 // VS: ListView_EditLabel requires that the list has focus.
aa50e893 1147 SetFocus();
edccf428 1148 HWND hWnd = (HWND) ListView_EditLabel(GetHwnd(), item);
bbcdf8bc
JS
1149
1150 if (m_textCtrl)
1151 {
0b5efdc7 1152 m_textCtrl->SetHWND(0);
7bf1474a 1153 m_textCtrl->UnsubclassWin();
0b5efdc7
VZ
1154 delete m_textCtrl;
1155 m_textCtrl = NULL;
bbcdf8bc
JS
1156 }
1157
1158 m_textCtrl = (wxTextCtrl*) textControlClass->CreateObject();
1159 m_textCtrl->SetHWND((WXHWND) hWnd);
1160 m_textCtrl->SubclassWin((WXHWND) hWnd);
1161
1162 return m_textCtrl;
1163}
1164
1165// End label editing, optionally cancelling the edit
33ac7e6f 1166bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel))
2bda0e17 1167{
7bf1474a
VZ
1168 wxFAIL_MSG( _T("not implemented") );
1169
0b5efdc7 1170 return FALSE;
2bda0e17
KB
1171}
1172
1173// Ensures this item is visible
debe6624 1174bool wxListCtrl::EnsureVisible(long item)
2bda0e17 1175{
7bf1474a 1176 return ListView_EnsureVisible(GetHwnd(), (int) item, FALSE) != 0;
2bda0e17
KB
1177}
1178
1179// Find an item whose label matches this string, starting from the item after 'start'
1180// or the beginning if 'start' is -1.
debe6624 1181long wxListCtrl::FindItem(long start, const wxString& str, bool partial)
2bda0e17 1182{
0b5efdc7 1183 LV_FINDINFO findInfo;
2bda0e17 1184
0b5efdc7
VZ
1185 findInfo.flags = LVFI_STRING;
1186 if ( partial )
7edc258e 1187 findInfo.flags |= LVFI_PARTIAL;
3ca6a5f0 1188 findInfo.psz = str;
2bda0e17 1189
3ca6a5f0
BP
1190 // ListView_FindItem() excludes the first item from search and to look
1191 // through all the items you need to start from -1 which is unnatural and
8036af01
JS
1192 // inconsistent with the generic version - so we adjust the index
1193 if (start != -1)
1194 start --;
1195 return ListView_FindItem(GetHwnd(), (int) start, &findInfo);
2bda0e17
KB
1196}
1197
1198// Find an item whose data matches this data, starting from the item after 'start'
1199// or the beginning if 'start' is -1.
debe6624 1200long wxListCtrl::FindItem(long start, long data)
2bda0e17 1201{
0b5efdc7 1202 LV_FINDINFO findInfo;
2bda0e17 1203
0b5efdc7
VZ
1204 findInfo.flags = LVFI_PARAM;
1205 findInfo.lParam = data;
2bda0e17 1206
edccf428 1207 return ListView_FindItem(GetHwnd(), (int) start, & findInfo);
2bda0e17
KB
1208}
1209
1210// Find an item nearest this position in the specified direction, starting from
1211// the item after 'start' or the beginning if 'start' is -1.
debe6624 1212long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction)
2bda0e17 1213{
0b5efdc7 1214 LV_FINDINFO findInfo;
2bda0e17 1215
0b5efdc7
VZ
1216 findInfo.flags = LVFI_NEARESTXY;
1217 findInfo.pt.x = pt.x;
1218 findInfo.pt.y = pt.y;
acb62b84 1219 findInfo.vkDirection = VK_RIGHT;
2bda0e17 1220
0b5efdc7
VZ
1221 if ( direction == wxLIST_FIND_UP )
1222 findInfo.vkDirection = VK_UP;
1223 else if ( direction == wxLIST_FIND_DOWN )
1224 findInfo.vkDirection = VK_DOWN;
1225 else if ( direction == wxLIST_FIND_LEFT )
1226 findInfo.vkDirection = VK_LEFT;
1227 else if ( direction == wxLIST_FIND_RIGHT )
1228 findInfo.vkDirection = VK_RIGHT;
1229
edccf428 1230 return ListView_FindItem(GetHwnd(), (int) start, & findInfo);
2bda0e17
KB
1231}
1232
1233// Determines which item (if any) is at the specified point,
1234// giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1235long wxListCtrl::HitTest(const wxPoint& point, int& flags)
1236{
1237 LV_HITTESTINFO hitTestInfo;
0b5efdc7
VZ
1238 hitTestInfo.pt.x = (int) point.x;
1239 hitTestInfo.pt.y = (int) point.y;
2bda0e17 1240
edccf428 1241 ListView_HitTest(GetHwnd(), & hitTestInfo);
2bda0e17 1242
0b5efdc7
VZ
1243 flags = 0;
1244 if ( hitTestInfo.flags & LVHT_ABOVE )
1245 flags |= wxLIST_HITTEST_ABOVE;
1246 if ( hitTestInfo.flags & LVHT_BELOW )
1247 flags |= wxLIST_HITTEST_BELOW;
1248 if ( hitTestInfo.flags & LVHT_NOWHERE )
1249 flags |= wxLIST_HITTEST_NOWHERE;
1250 if ( hitTestInfo.flags & LVHT_ONITEMICON )
1251 flags |= wxLIST_HITTEST_ONITEMICON;
1252 if ( hitTestInfo.flags & LVHT_ONITEMLABEL )
1253 flags |= wxLIST_HITTEST_ONITEMLABEL;
1254 if ( hitTestInfo.flags & LVHT_ONITEMSTATEICON )
1255 flags |= wxLIST_HITTEST_ONITEMSTATEICON;
1256 if ( hitTestInfo.flags & LVHT_TOLEFT )
1257 flags |= wxLIST_HITTEST_TOLEFT;
1258 if ( hitTestInfo.flags & LVHT_TORIGHT )
1259 flags |= wxLIST_HITTEST_TORIGHT;
1260
edccf428 1261 return (long) hitTestInfo.iItem;
2bda0e17
KB
1262}
1263
1264// Inserts an item, returning the index of the new item if successful,
1265// -1 otherwise.
2bda0e17
KB
1266long wxListCtrl::InsertItem(wxListItem& info)
1267{
98ec9dbe
VZ
1268 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1269
0b5efdc7
VZ
1270 LV_ITEM item;
1271 wxConvertToMSWListItem(this, info, item);
2bda0e17 1272
bdc72a22
VZ
1273 // check whether it has any custom attributes
1274 if ( info.HasAttributes() )
1275 {
2702ed5a 1276
35ec54d3
VS
1277 wxListItemAttr *attr;
1278 attr = (wxListItemAttr*) m_attrs.Get(item.iItem);
2702ed5a 1279
35ec54d3 1280 if (attr == NULL)
2702ed5a 1281
35ec54d3 1282 m_attrs.Put(item.iItem, (wxObject *)new wxListItemAttr(*info.GetAttributes()));
2702ed5a 1283
35ec54d3 1284 else *attr = *info.GetAttributes();
bdc72a22
VZ
1285
1286 m_hasAnyAttr = TRUE;
1287 }
bdc72a22 1288
edccf428 1289 return (long) ListView_InsertItem(GetHwnd(), & item);
2bda0e17
KB
1290}
1291
debe6624 1292long wxListCtrl::InsertItem(long index, const wxString& label)
2bda0e17 1293{
0b5efdc7
VZ
1294 wxListItem info;
1295 info.m_text = label;
1296 info.m_mask = wxLIST_MASK_TEXT;
1297 info.m_itemId = index;
1298 return InsertItem(info);
2bda0e17
KB
1299}
1300
1301// Inserts an image item
debe6624 1302long wxListCtrl::InsertItem(long index, int imageIndex)
2bda0e17 1303{
0b5efdc7
VZ
1304 wxListItem info;
1305 info.m_image = imageIndex;
1306 info.m_mask = wxLIST_MASK_IMAGE;
1307 info.m_itemId = index;
1308 return InsertItem(info);
2bda0e17
KB
1309}
1310
1311// Inserts an image/string item
debe6624 1312long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex)
2bda0e17 1313{
0b5efdc7
VZ
1314 wxListItem info;
1315 info.m_image = imageIndex;
1316 info.m_text = label;
1317 info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT;
1318 info.m_itemId = index;
1319 return InsertItem(info);
2bda0e17
KB
1320}
1321
1322// For list view mode (only), inserts a column.
debe6624 1323long wxListCtrl::InsertColumn(long col, wxListItem& item)
2bda0e17 1324{
0b5efdc7 1325 LV_COLUMN lvCol;
6f806543 1326 wxConvertToMSWListCol(col, item, lvCol);
0b5efdc7 1327
6f806543 1328 if ( !(lvCol.mask & LVCF_WIDTH) )
e373f51b
VZ
1329 {
1330 // always give some width to the new column: this one is compatible
6f806543
VZ
1331 // with the generic version
1332 lvCol.mask |= LVCF_WIDTH;
e373f51b 1333 lvCol.cx = 80;
0b5efdc7 1334 }
e373f51b 1335
6f806543
VZ
1336 // when we insert a column which can contain an image, we must specify this
1337 // flag right now as doing it later in SetColumn() has no effect
1338 //
1339 // we use LVCFMT_BITMAP_ON_RIGHT by default because without it there is no
1340 // way to dynamically set/clear the bitmap as the column without a bitmap
1341 // on the left looks ugly (there is a hole)
1342 //
1343 // unfortunately with my version of comctl32.dll (5.80), the left column
1344 // image is always on the left and it seems that it's a "feature" - I
1345 // didn't find any way to work around it in any case
1346 if ( lvCol.mask & LVCF_IMAGE )
1347 {
1348 lvCol.mask |= LVCF_FMT;
1349 lvCol.fmt |= LVCFMT_BITMAP_ON_RIGHT;
1350 }
2bda0e17 1351
6f806543 1352 bool success = ListView_InsertColumn(GetHwnd(), col, &lvCol) != -1;
2bda0e17 1353 if ( success )
e373f51b
VZ
1354 {
1355 m_colCount++;
1356 }
1357 else
1358 {
223d09f6 1359 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
e373f51b
VZ
1360 lvCol.pszText);
1361 }
1362
2bda0e17
KB
1363 return success;
1364}
1365
bdc72a22
VZ
1366long wxListCtrl::InsertColumn(long col,
1367 const wxString& heading,
1368 int format,
1369 int width)
2bda0e17 1370{
0b5efdc7
VZ
1371 wxListItem item;
1372 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
1373 item.m_text = heading;
1374 if ( width > -1 )
1375 {
1376 item.m_mask |= wxLIST_MASK_WIDTH;
1377 item.m_width = width;
1378 }
1379 item.m_format = format;
2bda0e17 1380
0b5efdc7 1381 return InsertColumn(col, item);
2bda0e17
KB
1382}
1383
1384// Scrolls the list control. If in icon, small icon or report view mode,
1385// x specifies the number of pixels to scroll. If in list view mode, x
1386// specifies the number of columns to scroll.
1387// If in icon, small icon or list view mode, y specifies the number of pixels
1388// to scroll. If in report view mode, y specifies the number of lines to scroll.
debe6624 1389bool wxListCtrl::ScrollList(int dx, int dy)
2bda0e17 1390{
edccf428 1391 return (ListView_Scroll(GetHwnd(), dx, dy) != 0);
2bda0e17
KB
1392}
1393
1394// Sort items.
1395
1396// fn is a function which takes 3 long arguments: item1, item2, data.
1397// item1 is the long data associated with a first item (NOT the index).
1398// item2 is the long data associated with a second item (NOT the index).
1399// data is the same value as passed to SortItems.
1400// The return value is a negative number if the first item should precede the second
1401// item, a positive number of the second item should precede the first,
1402// or zero if the two items are equivalent.
1403
1404// data is arbitrary data to be passed to the sort function.
19230604
RD
1405
1406// FIXME: this is horrible and MT-unsafe and everything else but I don't have
1407// time for anything better right now (VZ)
1408static long gs_sortData = 0;
1409static wxListCtrl *gs_sortCtrl = NULL;
1410static wxListCtrlCompare gs_sortFunction = NULL;
1411
1412int wxCMPFUNC_CONV wxListCtrlCompareFn(const void *arg1, const void *arg2)
1413{
1414 int n1 = *(const int *)arg1,
1415 n2 = *(const int *)arg2;
1416
1417 return gs_sortFunction(gs_sortCtrl->GetItemData(n1),
1418 gs_sortCtrl->GetItemData(n2),
1419 gs_sortData);
1420}
1421
2bda0e17
KB
1422bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data)
1423{
19230604
RD
1424 // sort the attributes too
1425 if ( m_hasAnyAttr )
1426 {
1427 int n,
1428 count = GetItemCount();
1429 int *aItems = new int[count];
1430 for ( n = 0; n < count; n++ )
1431 {
1432 aItems[n] = n;
1433 }
1434
1435 gs_sortData = data;
1436 gs_sortCtrl = this;
1437 gs_sortFunction = fn;
1438
1439 qsort(aItems, count, sizeof(int), wxListCtrlCompareFn);
1440
1441 gs_sortData = 0;
1442 gs_sortCtrl = NULL;
1443 gs_sortFunction = NULL;
1444
1445 wxHashTable attrsNew(wxKEY_INTEGER, 1000);
1446 for ( n = 0; n < count; n++ )
1447 {
7946d7de 1448 wxObject *attr = m_attrs.Delete(aItems[n]);
19230604
RD
1449 if ( attr )
1450 {
7946d7de 1451 attrsNew.Put(n, attr);
19230604
RD
1452 }
1453 }
1454
1455 m_attrs.Destroy();
1456 m_attrs = attrsNew;
1457
1458 delete [] aItems;
1459 }
1460
1461 if ( !ListView_SortItems(GetHwnd(), (PFNLVCOMPARE)fn, data) )
1462 {
1463 wxLogDebug(_T("ListView_SortItems() failed"));
1464
1465 return FALSE;
1466 }
1467
1468 return TRUE;
2bda0e17
KB
1469}
1470
19230604
RD
1471
1472
edccf428
VZ
1473// ----------------------------------------------------------------------------
1474// message processing
1475// ----------------------------------------------------------------------------
1476
debe6624 1477bool wxListCtrl::MSWCommand(WXUINT cmd, WXWORD id)
2bda0e17 1478{
0b5efdc7 1479 if (cmd == EN_UPDATE)
acb62b84 1480 {
0b5efdc7
VZ
1481 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, id);
1482 event.SetEventObject( this );
1483 ProcessCommand(event);
1484 return TRUE;
acb62b84 1485 }
0b5efdc7 1486 else if (cmd == EN_KILLFOCUS)
acb62b84 1487 {
0b5efdc7
VZ
1488 wxCommandEvent event(wxEVT_KILL_FOCUS, id);
1489 event.SetEventObject( this );
1490 ProcessCommand(event);
1491 return TRUE;
acb62b84 1492 }
edccf428
VZ
1493 else
1494 return FALSE;
0b5efdc7
VZ
1495}
1496
a23fd0e1 1497bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
0b5efdc7 1498{
bdc72a22
VZ
1499 // prepare the event
1500 // -----------------
1501
0b5efdc7 1502 wxListEvent event(wxEVT_NULL, m_windowId);
648bec3e
VZ
1503 event.SetEventObject(this);
1504
0b5efdc7 1505 wxEventType eventType = wxEVT_NULL;
225fe9d6 1506
bdc72a22 1507 NMHDR *nmhdr = (NMHDR *)lParam;
225fe9d6 1508
d1f2eb1d
VZ
1509 // if your compiler is as broken as this, you should really change it: this
1510 // code is needed for normal operation! #ifdef below is only useful for
1511 // automatic rebuilds which are done with a very old compiler version
0cf5b099 1512#ifdef HDN_BEGINTRACKA
d1f2eb1d 1513
11358d39
VZ
1514 // check for messages from the header (in report view)
1515 HWND hwndHdr = ListView_GetHeader(GetHwnd());
225fe9d6 1516
11358d39
VZ
1517 // is it a message from the header?
1518 if ( nmhdr->hwndFrom == hwndHdr )
acb62b84 1519 {
00811ff9 1520 HD_NOTIFY *nmHDR = (HD_NOTIFY *)nmhdr;
0cf5b099 1521
11358d39 1522 event.m_itemIndex = -1;
cb0f56f9 1523
11358d39
VZ
1524 switch ( nmhdr->code )
1525 {
1526 // yet another comctl32.dll bug: under NT/W2K it sends Unicode
1527 // TRACK messages even to ANSI programs: on my system I get
1528 // HDN_BEGINTRACKW and HDN_ENDTRACKA and no HDN_TRACK at all!
1529 //
1530 // work around is to simply catch both versions and hope that it
1531 // works (why should this message exist in ANSI and Unicode is
1532 // beyond me as it doesn't deal with strings at all...)
1533 case HDN_BEGINTRACKA:
1534 case HDN_BEGINTRACKW:
1535 eventType = wxEVT_COMMAND_LIST_COL_BEGIN_DRAG;
1536 // fall through
1537
1538 case HDN_TRACKA:
1539 case HDN_TRACKW:
1540 if ( eventType == wxEVT_NULL )
1541 eventType = wxEVT_COMMAND_LIST_COL_DRAGGING;
1542 // fall through
1543
1544 case HDN_ENDTRACKA:
1545 case HDN_ENDTRACKW:
1546 if ( eventType == wxEVT_NULL )
1547 eventType = wxEVT_COMMAND_LIST_COL_END_DRAG;
1548 event.m_col = nmHDR->iItem;
1549 break;
1550
1551 case NM_RCLICK:
1552 {
1553 eventType = wxEVT_COMMAND_LIST_COL_RIGHT_CLICK;
1554 event.m_col = -1;
0b5efdc7 1555
11358d39
VZ
1556 // find the column clicked: we have to search for it
1557 // ourselves as the notification message doesn't provide
1558 // this info
0b5efdc7 1559
11358d39
VZ
1560 // where did the click occur?
1561 POINT ptClick;
1562 if ( !::GetCursorPos(&ptClick) )
1563 {
1564 wxLogLastError(_T("GetCursorPos"));
1565 }
0b5efdc7 1566
11358d39
VZ
1567 if ( !::ScreenToClient(hwndHdr, &ptClick) )
1568 {
1569 wxLogLastError(_T("ScreenToClient(listctrl header)"));
1570 }
5ea47806 1571
11358d39
VZ
1572 event.m_pointDrag.x = ptClick.x;
1573 event.m_pointDrag.y = ptClick.y;
5ea47806 1574
11358d39 1575 int colCount = Header_GetItemCount(hwndHdr);
bdc72a22 1576
11358d39
VZ
1577 RECT rect;
1578 for ( int col = 0; col < colCount; col++ )
1579 {
1580 if ( Header_GetItemRect(hwndHdr, col, &rect) )
1581 {
1582 if ( ::PtInRect(&rect, ptClick) )
1583 {
1584 event.m_col = col;
1585 break;
1586 }
1587 }
1588 }
1589 }
1590 break;
5ea47806 1591
11358d39
VZ
1592 default:
1593 return wxControl::MSWOnNotify(idCtrl, lParam, result);
1594 }
1595 }
d1f2eb1d 1596 else
0cf5b099 1597#endif // defined(HDN_BEGINTRACKA)
d1f2eb1d 1598 if ( nmhdr->hwndFrom == GetHwnd() )
11358d39
VZ
1599 {
1600 // almost all messages use NM_LISTVIEW
1601 NM_LISTVIEW *nmLV = (NM_LISTVIEW *)nmhdr;
bdc72a22 1602
11358d39
VZ
1603 // this is true for almost all events
1604 event.m_item.m_data = nmLV->lParam;
bdc72a22 1605
11358d39
VZ
1606 switch ( nmhdr->code )
1607 {
1608 case LVN_BEGINRDRAG:
1609 eventType = wxEVT_COMMAND_LIST_BEGIN_RDRAG;
1610 // fall through
7bf1474a 1611
11358d39
VZ
1612 case LVN_BEGINDRAG:
1613 if ( eventType == wxEVT_NULL )
1614 {
1615 eventType = wxEVT_COMMAND_LIST_BEGIN_DRAG;
1616 }
bdc72a22 1617
11358d39
VZ
1618 event.m_itemIndex = nmLV->iItem;
1619 event.m_pointDrag.x = nmLV->ptAction.x;
1620 event.m_pointDrag.y = nmLV->ptAction.y;
1621 break;
1622
1623 case LVN_BEGINLABELEDIT:
1624 {
1625 eventType = wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT;
1626 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1627 wxConvertFromMSWListItem(GetHwnd(), event.m_item, info->item);
1628 event.m_itemIndex = event.m_item.m_itemId;
1629 }
1630 break;
edccf428 1631
11358d39
VZ
1632 case LVN_COLUMNCLICK:
1633 eventType = wxEVT_COMMAND_LIST_COL_CLICK;
1634 event.m_itemIndex = -1;
1635 event.m_col = nmLV->iSubItem;
1636 break;
bdc72a22 1637
11358d39
VZ
1638 case LVN_DELETEALLITEMS:
1639 eventType = wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS;
1640 event.m_itemIndex = -1;
1641
1642 FreeAllAttrs();
1643
1644 break;
1645
1646 case LVN_DELETEITEM:
1647 eventType = wxEVT_COMMAND_LIST_DELETE_ITEM;
225fe9d6 1648 event.m_itemIndex = nmLV->iItem;
11358d39
VZ
1649
1650 if ( m_hasAnyAttr )
1651 {
1652 delete (wxListItemAttr *)m_attrs.Delete(nmLV->iItem);
1653 }
1654 break;
1655
1656 case LVN_ENDLABELEDIT:
1657 {
1658 eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT;
1659 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
8ecd8ade 1660 wxConvertFromMSWListItem(NULL, event.m_item, info->item);
11358d39
VZ
1661 if ( info->item.pszText == NULL || info->item.iItem == -1 )
1662 return FALSE;
1663
1664 event.m_itemIndex = event.m_item.m_itemId;
1665 }
1666 break;
1667
1668 case LVN_SETDISPINFO:
1669 {
1670 eventType = wxEVT_COMMAND_LIST_SET_INFO;
1671 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1672 wxConvertFromMSWListItem(GetHwnd(), event.m_item, info->item);
1673 }
1674 break;
1675
1676 case LVN_INSERTITEM:
1677 eventType = wxEVT_COMMAND_LIST_INSERT_ITEM;
225fe9d6 1678 event.m_itemIndex = nmLV->iItem;
11358d39 1679 break;
edccf428 1680
11358d39 1681 case LVN_ITEMCHANGED:
648bec3e
VZ
1682 // we translate this catch all message into more interesting
1683 // (and more easy to process) wxWindows events
1684
1685 // first of all, we deal with the state change events only
1686 if ( nmLV->uChanged & LVIF_STATE )
11358d39 1687 {
648bec3e
VZ
1688 // temp vars for readability
1689 const UINT stOld = nmLV->uOldState;
1690 const UINT stNew = nmLV->uNewState;
1691
1692 // has the focus changed?
1693 if ( !(stOld & LVIS_FOCUSED) && (stNew & LVIS_FOCUSED) )
1694 {
1695 eventType = wxEVT_COMMAND_LIST_ITEM_FOCUSED;
1696 event.m_itemIndex = nmLV->iItem;
1697 }
1698
1699 if ( (stNew & LVIS_SELECTED) != (stOld & LVIS_SELECTED) )
1700 {
1701 if ( eventType != wxEVT_NULL )
1702 {
1703 // focus and selection have both changed: send the
1704 // focus event from here and the selection one
1705 // below
1706 event.SetEventType(eventType);
1707 (void)GetEventHandler()->ProcessEvent(event);
1708 }
1709 else // no focus event to send
1710 {
1711 // then need to set m_itemIndex as it wasn't done
1712 // above
1713 event.m_itemIndex = nmLV->iItem;
1714 }
1715
1716 eventType = stNew & LVIS_SELECTED
1717 ? wxEVT_COMMAND_LIST_ITEM_SELECTED
1718 : wxEVT_COMMAND_LIST_ITEM_DESELECTED;
1719 }
edccf428 1720 }
648bec3e
VZ
1721
1722 if ( eventType == wxEVT_NULL )
edccf428 1723 {
648bec3e 1724 // not an interesting event for us
11358d39 1725 return FALSE;
edccf428 1726 }
648bec3e 1727
11358d39 1728 break;
225fe9d6 1729
11358d39
VZ
1730 case LVN_KEYDOWN:
1731 {
1732 LV_KEYDOWN *info = (LV_KEYDOWN *)lParam;
1733 WORD wVKey = info->wVKey;
1734
1735 // get the current selection
1736 long lItem = GetNextItem(-1,
1737 wxLIST_NEXT_ALL,
1738 wxLIST_STATE_SELECTED);
1739
1740 // <Enter> or <Space> activate the selected item if any (but
1741 // not with Shift and/or Ctrl as then they have a predefined
1742 // meaning for the list view)
1743 if ( lItem != -1 &&
1744 (wVKey == VK_RETURN || wVKey == VK_SPACE) &&
1745 !(wxIsShiftDown() || wxIsCtrlDown()) )
1746 {
1747 eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
1748 }
1749 else
1750 {
1751 eventType = wxEVT_COMMAND_LIST_KEY_DOWN;
185d0094
VZ
1752
1753 // wxCharCodeMSWToWX() returns 0 if the key is an ASCII
1754 // value which should be used as is
1755 int code = wxCharCodeMSWToWX(wVKey);
1756 event.m_code = code ? code : wVKey;
11358d39 1757 }
7db91489 1758
11358d39
VZ
1759 event.m_itemIndex =
1760 event.m_item.m_itemId = lItem;
1761
1762 if ( lItem != -1 )
1763 {
1764 // fill the other fields too
1765 event.m_item.m_text = GetItemText(lItem);
1766 event.m_item.m_data = GetItemData(lItem);
1767 }
1768 }
1769 break;
1770
1771 case NM_DBLCLK:
1772 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1773 // anything else
1774 if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
f6bcfd97 1775 {
11358d39 1776 return TRUE;
f6bcfd97 1777 }
edccf428 1778
11358d39
VZ
1779 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
1780 // if it happened on an item (and not on empty place)
1781 if ( nmLV->iItem == -1 )
1782 {
1783 // not on item
1784 return FALSE;
1785 }
edccf428 1786
11358d39
VZ
1787 eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
1788 event.m_itemIndex = nmLV->iItem;
1789 event.m_item.m_text = GetItemText(nmLV->iItem);
1790 event.m_item.m_data = GetItemData(nmLV->iItem);
1791 break;
225fe9d6 1792
11358d39 1793 case NM_RCLICK:
225fe9d6
VZ
1794 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
1795 // don't do anything else
1796 if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
1797 {
1798 return TRUE;
1799 }
cb0f56f9 1800
225fe9d6
VZ
1801 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1802 LV_HITTESTINFO lvhti;
1803 wxZeroMemory(lvhti);
11c7d5b6 1804
225fe9d6
VZ
1805 ::GetCursorPos(&(lvhti.pt));
1806 ::ScreenToClient(GetHwnd(),&(lvhti.pt));
1807 if ( ListView_HitTest(GetHwnd(),&lvhti) != -1 )
cb0f56f9 1808 {
225fe9d6
VZ
1809 if ( lvhti.flags & LVHT_ONITEM )
1810 {
1811 eventType = wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK;
1812 event.m_itemIndex = lvhti.iItem;
a1f79c1e
VZ
1813 event.m_pointDrag.x = lvhti.pt.x;
1814 event.m_pointDrag.y = lvhti.pt.y;
225fe9d6 1815 }
cb0f56f9 1816 }
11358d39 1817 break;
bdc72a22 1818
bf9b6266 1819#if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
11358d39
VZ
1820 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
1821 case NM_CUSTOMDRAW:
1822 *result = OnCustomDraw(lParam);
63166611 1823
11358d39 1824 return TRUE;
6ecfe2ac 1825#endif // _WIN32_IE >= 0x300
0b5efdc7 1826
11358d39
VZ
1827 case LVN_ODCACHEHINT:
1828 {
1829 const NM_CACHEHINT *cacheHint = (NM_CACHEHINT *)lParam;
614391dc 1830
11358d39 1831 eventType = wxEVT_COMMAND_LIST_CACHE_HINT;
e623926d 1832
11358d39
VZ
1833 // we get some really stupid cache hints like ones for items in
1834 // range 0..0 for an empty control or, after deleting an item,
1835 // for items in invalid range - filter this garbage out
1836 if ( cacheHint->iFrom < cacheHint->iTo )
1837 {
1838 event.m_oldItemIndex = cacheHint->iFrom;
e623926d 1839
11358d39
VZ
1840 long iMax = GetItemCount();
1841 event.m_itemIndex = cacheHint->iTo < iMax ? cacheHint->iTo
1842 : iMax - 1;
1843 }
1844 else
1845 {
1846 return FALSE;
1847 }
e623926d 1848 }
11358d39 1849 break;
614391dc 1850
11358d39
VZ
1851 case LVN_GETDISPINFO:
1852 if ( IsVirtual() )
1853 {
1854 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
98ec9dbe 1855
11358d39
VZ
1856 LV_ITEM& lvi = info->item;
1857 long item = lvi.iItem;
98ec9dbe 1858
11358d39
VZ
1859 if ( lvi.mask & LVIF_TEXT )
1860 {
1861 wxString text = OnGetItemText(item, lvi.iSubItem);
1862 wxStrncpy(lvi.pszText, text, lvi.cchTextMax);
1863 }
98ec9dbe 1864
244531bc 1865#if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
5145e34f 1866 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) )
11358d39
VZ
1867 if ( lvi.mask & LVIF_IMAGE )
1868 {
1869 lvi.iImage = OnGetItemImage(item);
1870 }
244531bc 1871#endif
98ec9dbe 1872
11358d39
VZ
1873 // a little dose of healthy paranoia: as we never use
1874 // LVM_SETCALLBACKMASK we're not supposed to get these ones
1875 wxASSERT_MSG( !(lvi.mask & LVIF_STATE),
1876 _T("we don't support state callbacks yet!") );
98ec9dbe 1877
11358d39
VZ
1878 return TRUE;
1879 }
1880 // fall through
98ec9dbe 1881
11358d39
VZ
1882 default:
1883 return wxControl::MSWOnNotify(idCtrl, lParam, result);
1884 }
1885 }
1886 else
1887 {
1888 // where did this one come from?
1889 return FALSE;
acb62b84
VZ
1890 }
1891
bdc72a22
VZ
1892 // process the event
1893 // -----------------
1894
0b5efdc7 1895 event.SetEventType(eventType);
acb62b84 1896
0b5efdc7
VZ
1897 if ( !GetEventHandler()->ProcessEvent(event) )
1898 return FALSE;
acb62b84 1899
bdc72a22
VZ
1900 // post processing
1901 // ---------------
1902
225fe9d6 1903 switch ( nmhdr->code )
acb62b84 1904 {
6932a32c
VZ
1905 case LVN_DELETEALLITEMS:
1906 // always return TRUE to suppress all additional LVN_DELETEITEM
1907 // notifications - this makes deleting all items from a list ctrl
1908 // much faster
1909 *result = TRUE;
1910
1911 return TRUE;
1912
1ee4ead5 1913 case LVN_ENDLABELEDIT:
614391dc
VZ
1914 // logic here is inversed compared to all the other messages
1915 *result = event.IsAllowed();
1916
1917 return TRUE;
acb62b84 1918 }
acb62b84 1919
0b5efdc7 1920 *result = !event.IsAllowed();
fd3f686c 1921
0b5efdc7 1922 return TRUE;
2bda0e17
KB
1923}
1924
63166611
VZ
1925#if defined(_WIN32_IE) && _WIN32_IE >= 0x300
1926
1927WXLPARAM wxListCtrl::OnCustomDraw(WXLPARAM lParam)
1928{
1929 LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
1930 NMCUSTOMDRAW& nmcd = lplvcd->nmcd;
1931 switch ( nmcd.dwDrawStage )
1932 {
1933 case CDDS_PREPAINT:
1934 // if we've got any items with non standard attributes,
1935 // notify us before painting each item
1936 //
1937 // for virtual controls, always suppose that we have attributes as
1938 // there is no way to check for this
1939 return IsVirtual() || m_hasAnyAttr ? CDRF_NOTIFYITEMDRAW
1940 : CDRF_DODEFAULT;
1941
1942 case CDDS_ITEMPREPAINT:
1943 {
1944 size_t item = (size_t)nmcd.dwItemSpec;
a7f560a2
VZ
1945 if ( item >= (size_t)GetItemCount() )
1946 {
1947 // we get this message with item == 0 for an empty control,
1948 // we must ignore it as calling OnGetItemAttr() would be
1949 // wrong
1950 return CDRF_DODEFAULT;
1951 }
1952
63166611
VZ
1953 wxListItemAttr *attr =
1954 IsVirtual() ? OnGetItemAttr(item)
1955 : (wxListItemAttr *)m_attrs.Get(item);
1956
1957 if ( !attr )
1958 {
1959 // nothing to do for this item
1960 return CDRF_DODEFAULT;
1961 }
1962
1963 HFONT hFont;
1964 wxColour colText, colBack;
1965 if ( attr->HasFont() )
1966 {
1967 wxFont font = attr->GetFont();
1968 hFont = (HFONT)font.GetResourceHandle();
1969 }
1970 else
1971 {
1972 hFont = 0;
1973 }
1974
1975 if ( attr->HasTextColour() )
1976 {
1977 colText = attr->GetTextColour();
1978 }
1979 else
1980 {
1981 colText = GetTextColour();
1982 }
1983
1984 if ( attr->HasBackgroundColour() )
1985 {
1986 colBack = attr->GetBackgroundColour();
1987 }
1988 else
1989 {
1990 colBack = GetBackgroundColour();
1991 }
1992
1993 lplvcd->clrText = wxColourToRGB(colText);
1994 lplvcd->clrTextBk = wxColourToRGB(colBack);
1995
1996 // note that if we wanted to set colours for
1997 // individual columns (subitems), we would have
1998 // returned CDRF_NOTIFYSUBITEMREDRAW from here
1999 if ( hFont )
2000 {
2001 ::SelectObject(nmcd.hdc, hFont);
2002
2003 return CDRF_NEWFONT;
2004 }
2005 }
2006 // fall through to return CDRF_DODEFAULT
2007
2008 default:
2009 return CDRF_DODEFAULT;
2010 }
2011}
2012
2013#endif // NM_CUSTOMDRAW supported
2014
2702ed5a
JS
2015// Necessary for drawing hrules and vrules, if specified
2016void wxListCtrl::OnPaint(wxPaintEvent& event)
2017{
2018 wxPaintDC dc(this);
2019
2020 wxControl::OnPaint(event);
2021
2022 // Reset the device origin since it may have been set
2023 dc.SetDeviceOrigin(0, 0);
2024
2025 bool drawHRules = ((GetWindowStyle() & wxLC_HRULES) != 0);
2026 bool drawVRules = ((GetWindowStyle() & wxLC_VRULES) != 0);
2027
2028 if (!drawHRules && !drawVRules)
2029 return;
2030 if ((GetWindowStyle() & wxLC_REPORT) == 0)
2031 return;
2032
a756f210 2033 wxPen pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
2702ed5a
JS
2034 dc.SetPen(pen);
2035 dc.SetBrush(* wxTRANSPARENT_BRUSH);
2036
2037 wxSize clientSize = GetClientSize();
2038 wxRect itemRect;
2039 int cy=0;
2040
2702ed5a
JS
2041 int itemCount = GetItemCount();
2042 int i;
625cb8c0 2043 if (drawHRules)
2702ed5a 2044 {
6443de02
RD
2045 long top = GetTopItem();
2046 for (i = top; i < top + GetCountPerPage() + 1; i++)
2702ed5a 2047 {
625cb8c0 2048 if (GetItemRect(i, itemRect))
ca286917 2049 {
625cb8c0
RD
2050 cy = itemRect.GetTop();
2051 if (i != 0) // Don't draw the first one
2052 {
2053 dc.DrawLine(0, cy, clientSize.x, cy);
2054 }
2055 // Draw last line
2cefcb34 2056 if (i == itemCount - 1)
625cb8c0
RD
2057 {
2058 cy = itemRect.GetBottom();
2059 dc.DrawLine(0, cy, clientSize.x, cy);
2060 }
2702ed5a
JS
2061 }
2062 }
2063 }
2cefcb34 2064 i = itemCount - 1;
2702ed5a
JS
2065 if (drawVRules && (i > -1))
2066 {
2067 wxRect firstItemRect;
2068 GetItemRect(0, firstItemRect);
2069
2070 if (GetItemRect(i, itemRect))
2071 {
2072 int col;
2073 int x = itemRect.GetX();
2074 for (col = 0; col < GetColumnCount(); col++)
2075 {
2076 int colWidth = GetColumnWidth(col);
2077 x += colWidth ;
2078 dc.DrawLine(x, firstItemRect.GetY() - 2, x, itemRect.GetBottom());
2079 }
2080 }
2081 }
2082}
2083
98ec9dbe
VZ
2084// ----------------------------------------------------------------------------
2085// virtual list controls
2086// ----------------------------------------------------------------------------
2087
d699f48b 2088wxString wxListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const
98ec9dbe
VZ
2089{
2090 // this is a pure virtual function, in fact - which is not really pure
2091 // because the controls which are not virtual don't need to implement it
2092 wxFAIL_MSG( _T("not supposed to be called") );
2093
2094 return wxEmptyString;
2095}
2096
d699f48b 2097int wxListCtrl::OnGetItemImage(long WXUNUSED(item)) const
98ec9dbe
VZ
2098{
2099 // same as above
2100 wxFAIL_MSG( _T("not supposed to be called") );
2101
2102 return -1;
2103}
2104
d699f48b 2105wxListItemAttr *wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)) const
6c02c329 2106{
63166611 2107 wxASSERT_MSG( item >= 0 && item < GetItemCount(),
6c02c329
VZ
2108 _T("invalid item index in OnGetItemAttr()") );
2109
2110 // no attributes by default
2111 return NULL;
2112}
2113
98ec9dbe
VZ
2114void wxListCtrl::SetItemCount(long count)
2115{
2116 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2117
2118 if ( !::SendMessage(GetHwnd(), LVM_SETITEMCOUNT, (WPARAM)count, 0) )
2119 {
2120 wxLogLastError(_T("ListView_SetItemCount"));
2121 }
2122}
2123
a7f560a2
VZ
2124void wxListCtrl::RefreshItem(long item)
2125{
2d33aec9
VZ
2126 // strangely enough, ListView_Update() results in much more flicker here
2127 // than a dumb Refresh() -- why?
2128#if 0
a7f560a2
VZ
2129 if ( !ListView_Update(GetHwnd(), item) )
2130 {
2131 wxLogLastError(_T("ListView_Update"));
2132 }
2d33aec9
VZ
2133#else // 1
2134 wxRect rect;
2135 GetItemRect(item, rect);
2136 RefreshRect(rect);
2137#endif // 0/1
a7f560a2
VZ
2138}
2139
2140void wxListCtrl::RefreshItems(long itemFrom, long itemTo)
2141{
d0debf52
VZ
2142 wxRect rect1, rect2;
2143 GetItemRect(itemFrom, rect1);
2144 GetItemRect(itemTo, rect2);
2145
2146 wxRect rect = rect1;
2147 rect.height = rect2.GetBottom() - rect1.GetTop();
2148
2149 RefreshRect(rect);
a7f560a2
VZ
2150}
2151
edccf428
VZ
2152// ----------------------------------------------------------------------------
2153// wxListItem
2154// ----------------------------------------------------------------------------
2155
2bda0e17 2156// List item structure
0b5efdc7 2157wxListItem::wxListItem()
2bda0e17
KB
2158{
2159 m_mask = 0;
2160 m_itemId = 0;
2161 m_col = 0;
2162 m_state = 0;
2163 m_stateMask = 0;
2164 m_image = 0;
0b5efdc7 2165 m_data = 0;
2bda0e17 2166
0b5efdc7
VZ
2167 m_format = wxLIST_FORMAT_CENTRE;
2168 m_width = 0;
bdc72a22
VZ
2169
2170 m_attr = NULL;
2bda0e17
KB
2171}
2172
9b00bb16
RR
2173void wxListItem::Clear()
2174{
2175 m_mask = 0;
2176 m_itemId = 0;
2177 m_col = 0;
2178 m_state = 0;
2179 m_stateMask = 0;
2180 m_image = 0;
2181 m_data = 0;
2182 m_format = wxLIST_FORMAT_CENTRE;
2183 m_width = 0;
2184 m_text = wxEmptyString;
2185
2186 if (m_attr) delete m_attr;
2187 m_attr = NULL;
2188}
2189
2190void wxListItem::ClearAttributes()
2191{
2192 if (m_attr) delete m_attr;
2193 m_attr = NULL;
2194}
2195
8dff2b5c
VZ
2196static void wxConvertFromMSWListItem(HWND hwndListCtrl,
2197 wxListItem& info,
2198 LV_ITEM& lvItem)
2bda0e17 2199{
0b5efdc7
VZ
2200 info.m_data = lvItem.lParam;
2201 info.m_mask = 0;
2202 info.m_state = 0;
2203 info.m_stateMask = 0;
2204 info.m_itemId = lvItem.iItem;
acb62b84 2205
0b5efdc7 2206 long oldMask = lvItem.mask;
acb62b84 2207
0b5efdc7 2208 bool needText = FALSE;
8dff2b5c 2209 if (hwndListCtrl != 0)
acb62b84 2210 {
0b5efdc7
VZ
2211 if ( lvItem.mask & LVIF_TEXT )
2212 needText = FALSE;
2213 else
2214 needText = TRUE;
acb62b84 2215
0b5efdc7
VZ
2216 if ( needText )
2217 {
837e5743 2218 lvItem.pszText = new wxChar[513];
0b5efdc7
VZ
2219 lvItem.cchTextMax = 512;
2220 }
edccf428 2221 lvItem.mask |= LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
8dff2b5c 2222 ::SendMessage(hwndListCtrl, LVM_GETITEM, 0, (LPARAM)& lvItem);
0b5efdc7 2223 }
acb62b84 2224
0b5efdc7 2225 if ( lvItem.mask & LVIF_STATE )
acb62b84 2226 {
0b5efdc7
VZ
2227 info.m_mask |= wxLIST_MASK_STATE;
2228
2229 if ( lvItem.stateMask & LVIS_CUT)
2230 {
edccf428 2231 info.m_stateMask |= wxLIST_STATE_CUT;
0b5efdc7 2232 if ( lvItem.state & LVIS_CUT )
edccf428 2233 info.m_state |= wxLIST_STATE_CUT;
0b5efdc7
VZ
2234 }
2235 if ( lvItem.stateMask & LVIS_DROPHILITED)
2236 {
edccf428 2237 info.m_stateMask |= wxLIST_STATE_DROPHILITED;
0b5efdc7 2238 if ( lvItem.state & LVIS_DROPHILITED )
edccf428 2239 info.m_state |= wxLIST_STATE_DROPHILITED;
0b5efdc7
VZ
2240 }
2241 if ( lvItem.stateMask & LVIS_FOCUSED)
2242 {
edccf428 2243 info.m_stateMask |= wxLIST_STATE_FOCUSED;
0b5efdc7 2244 if ( lvItem.state & LVIS_FOCUSED )
edccf428 2245 info.m_state |= wxLIST_STATE_FOCUSED;
0b5efdc7
VZ
2246 }
2247 if ( lvItem.stateMask & LVIS_SELECTED)
2248 {
edccf428 2249 info.m_stateMask |= wxLIST_STATE_SELECTED;
0b5efdc7 2250 if ( lvItem.state & LVIS_SELECTED )
edccf428 2251 info.m_state |= wxLIST_STATE_SELECTED;
0b5efdc7 2252 }
acb62b84 2253 }
0b5efdc7
VZ
2254
2255 if ( lvItem.mask & LVIF_TEXT )
acb62b84 2256 {
0b5efdc7
VZ
2257 info.m_mask |= wxLIST_MASK_TEXT;
2258 info.m_text = lvItem.pszText;
acb62b84 2259 }
0b5efdc7 2260 if ( lvItem.mask & LVIF_IMAGE )
acb62b84 2261 {
0b5efdc7
VZ
2262 info.m_mask |= wxLIST_MASK_IMAGE;
2263 info.m_image = lvItem.iImage;
acb62b84 2264 }
0b5efdc7
VZ
2265 if ( lvItem.mask & LVIF_PARAM )
2266 info.m_mask |= wxLIST_MASK_DATA;
2267 if ( lvItem.mask & LVIF_DI_SETITEM )
2268 info.m_mask |= wxLIST_SET_ITEM;
2269 info.m_col = lvItem.iSubItem;
2270
2271 if (needText)
acb62b84 2272 {
0b5efdc7
VZ
2273 if (lvItem.pszText)
2274 delete[] lvItem.pszText;
acb62b84 2275 }
edccf428 2276 lvItem.mask = oldMask;
2bda0e17
KB
2277}
2278
8dff2b5c
VZ
2279static void wxConvertToMSWFlags(long state, long stateMask, LV_ITEM& lvItem)
2280{
2281 if (stateMask & wxLIST_STATE_CUT)
2282 {
2283 lvItem.stateMask |= LVIS_CUT;
2284 if (state & wxLIST_STATE_CUT)
2285 lvItem.state |= LVIS_CUT;
2286 }
2287 if (stateMask & wxLIST_STATE_DROPHILITED)
2288 {
2289 lvItem.stateMask |= LVIS_DROPHILITED;
2290 if (state & wxLIST_STATE_DROPHILITED)
2291 lvItem.state |= LVIS_DROPHILITED;
2292 }
2293 if (stateMask & wxLIST_STATE_FOCUSED)
2294 {
2295 lvItem.stateMask |= LVIS_FOCUSED;
2296 if (state & wxLIST_STATE_FOCUSED)
2297 lvItem.state |= LVIS_FOCUSED;
2298 }
2299 if (stateMask & wxLIST_STATE_SELECTED)
2300 {
2301 lvItem.stateMask |= LVIS_SELECTED;
2302 if (state & wxLIST_STATE_SELECTED)
2303 lvItem.state |= LVIS_SELECTED;
2304 }
2305}
2306
2307static void wxConvertToMSWListItem(const wxListCtrl *ctrl,
2308 const wxListItem& info,
2309 LV_ITEM& lvItem)
2bda0e17 2310{
edccf428 2311 lvItem.iItem = (int) info.m_itemId;
acb62b84 2312
edccf428 2313 lvItem.iImage = info.m_image;
0b5efdc7
VZ
2314 lvItem.lParam = info.m_data;
2315 lvItem.stateMask = 0;
2316 lvItem.state = 0;
2317 lvItem.mask = 0;
2318 lvItem.iSubItem = info.m_col;
acb62b84 2319
0b5efdc7 2320 if (info.m_mask & wxLIST_MASK_STATE)
acb62b84 2321 {
edccf428 2322 lvItem.mask |= LVIF_STATE;
8dff2b5c
VZ
2323
2324 wxConvertToMSWFlags(info.m_state, info.m_stateMask, lvItem);
acb62b84 2325 }
acb62b84 2326
0b5efdc7 2327 if (info.m_mask & wxLIST_MASK_TEXT)
acb62b84 2328 {
edccf428 2329 lvItem.mask |= LVIF_TEXT;
0b5efdc7
VZ
2330 if ( ctrl->GetWindowStyleFlag() & wxLC_USER_TEXT )
2331 {
2332 lvItem.pszText = LPSTR_TEXTCALLBACK;
2333 }
2334 else
2335 {
e421922f
VZ
2336 // pszText is not const, hence the cast
2337 lvItem.pszText = (wxChar *)info.m_text.c_str();
0b5efdc7
VZ
2338 if ( lvItem.pszText )
2339 lvItem.cchTextMax = info.m_text.Length();
2340 else
2341 lvItem.cchTextMax = 0;
2342 }
acb62b84 2343 }
0b5efdc7 2344 if (info.m_mask & wxLIST_MASK_IMAGE)
edccf428 2345 lvItem.mask |= LVIF_IMAGE;
0b5efdc7 2346 if (info.m_mask & wxLIST_MASK_DATA)
edccf428 2347 lvItem.mask |= LVIF_PARAM;
2bda0e17
KB
2348}
2349
574c939e 2350static void wxConvertToMSWListCol(int WXUNUSED(col), const wxListItem& item,
6f806543
VZ
2351 LV_COLUMN& lvCol)
2352{
2353 wxZeroMemory(lvCol);
2354
2355 if ( item.m_mask & wxLIST_MASK_TEXT )
2356 {
2357 lvCol.mask |= LVCF_TEXT;
2358 lvCol.pszText = (wxChar *)item.m_text.c_str(); // cast is safe
2359 }
2360
2361 if ( item.m_mask & wxLIST_MASK_FORMAT )
2362 {
2363 lvCol.mask |= LVCF_FMT;
2364
2365 if ( item.m_format == wxLIST_FORMAT_LEFT )
2366 lvCol.fmt = LVCFMT_LEFT;
2367 else if ( item.m_format == wxLIST_FORMAT_RIGHT )
2368 lvCol.fmt = LVCFMT_RIGHT;
2369 else if ( item.m_format == wxLIST_FORMAT_CENTRE )
2370 lvCol.fmt = LVCFMT_CENTER;
2371 }
2372
2373 if ( item.m_mask & wxLIST_MASK_WIDTH )
2374 {
2375 lvCol.mask |= LVCF_WIDTH;
2376 if ( item.m_width == wxLIST_AUTOSIZE)
2377 lvCol.cx = LVSCW_AUTOSIZE;
2378 else if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER)
2379 lvCol.cx = LVSCW_AUTOSIZE_USEHEADER;
2380 else
2381 lvCol.cx = item.m_width;
2382 }
2383
244531bc 2384#if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
5145e34f 2385 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) )
6f806543
VZ
2386 if ( item.m_mask & wxLIST_MASK_IMAGE )
2387 {
2388 if ( wxTheApp->GetComCtl32Version() >= 470 )
2389 {
2390 lvCol.mask |= LVCF_IMAGE;
2391 lvCol.iImage = item.m_image;
2392 }
2393 //else: it doesn't support item images anyhow
2394 }
244531bc 2395#endif
6f806543
VZ
2396}
2397
1e6feb95 2398#endif // wxUSE_LISTCTRL