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