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