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