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