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