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