]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
648bec3e | 2 | // Name: src/msw/listctrl.cpp |
2bda0e17 KB |
3 | // Purpose: wxListCtrl |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa JS |
8 | // Copyright: (c) Julian Smart |
9 | // Licence: wxWindows licence | |
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 | ||
7391216e | 54 | #include "wx/msw/missing.h" |
12979259 | 55 | |
edccf428 VZ |
56 | // ---------------------------------------------------------------------------- |
57 | // private functions | |
58 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 59 | |
8dff2b5c VZ |
60 | // convert our state and mask flags to LV_ITEM constants |
61 | static void wxConvertToMSWFlags(long state, long mask, LV_ITEM& lvItem); | |
62 | ||
63 | // convert wxListItem to LV_ITEM | |
64 | static void wxConvertToMSWListItem(const wxListCtrl *ctrl, | |
65 | const wxListItem& info, LV_ITEM& lvItem); | |
66 | ||
67 | // convert LV_ITEM to wxListItem | |
68 | static void wxConvertFromMSWListItem(HWND hwndListCtrl, | |
69 | wxListItem& info, | |
70 | /* const */ LV_ITEM& lvItem); | |
2bda0e17 | 71 | |
6f806543 VZ |
72 | // convert our wxListItem to LV_COLUMN |
73 | static void wxConvertToMSWListCol(int col, const wxListItem& item, | |
74 | LV_COLUMN& lvCol); | |
75 | ||
8c21905b VS |
76 | // ---------------------------------------------------------------------------- |
77 | // private helper classes | |
78 | // ---------------------------------------------------------------------------- | |
79 | ||
80 | // We have to handle both fooW and fooA notifications in several cases | |
81 | // because of broken commctl.dll and/or unicows.dll. This class is used to | |
73d8c5fd | 82 | // convert LV_ITEMA and LV_ITEMW to LV_ITEM (which is either LV_ITEMA or |
8c21905b VS |
83 | // LV_ITEMW depending on wxUSE_UNICODE setting), so that it can be processed |
84 | // by wxConvertToMSWListItem(). | |
85 | class wxLV_ITEM | |
86 | { | |
87 | public: | |
88 | ~wxLV_ITEM() { delete m_buf; } | |
89 | operator LV_ITEM&() const { return *m_item; } | |
90 | ||
91 | #if wxUSE_UNICODE | |
92 | wxLV_ITEM(LV_ITEMW &item) : m_buf(NULL), m_item(&item) {} | |
93 | wxLV_ITEM(LV_ITEMA &item) | |
94 | { | |
95 | m_item = new LV_ITEM((LV_ITEM&)item); | |
96 | if ( (item.mask & LVIF_TEXT) && item.pszText ) | |
97 | { | |
98 | m_buf = new wxMB2WXbuf(wxConvLocal.cMB2WX(item.pszText)); | |
99 | m_item->pszText = (wxChar*)m_buf->data(); | |
100 | } | |
101 | else | |
102 | m_buf = NULL; | |
73d8c5fd | 103 | } |
8c21905b VS |
104 | private: |
105 | wxMB2WXbuf *m_buf; | |
106 | ||
2b5f62a0 | 107 | #else // !wxUSE_UNICODE |
8c21905b VS |
108 | wxLV_ITEM(LV_ITEMW &item) |
109 | { | |
110 | m_item = new LV_ITEM((LV_ITEM&)item); | |
2b5f62a0 VZ |
111 | |
112 | // the code below doesn't compile without wxUSE_WCHAR_T and as I don't | |
113 | // know if it's useful to have it at all (do we ever get Unicode | |
114 | // notifications in ANSI mode? I don't think so...) I'm not going to | |
115 | // write alternative implementation right now | |
116 | // | |
117 | // but if it is indeed used, we should simply directly use | |
118 | // ::WideCharToMultiByte() here | |
119 | #if wxUSE_WCHAR_T | |
8c21905b VS |
120 | if ( (item.mask & LVIF_TEXT) && item.pszText ) |
121 | { | |
122 | m_buf = new wxWC2WXbuf(wxConvLocal.cWC2WX(item.pszText)); | |
123 | m_item->pszText = (wxChar*)m_buf->data(); | |
124 | } | |
125 | else | |
2b5f62a0 | 126 | #endif // wxUSE_WCHAR_T |
8c21905b | 127 | m_buf = NULL; |
73d8c5fd | 128 | } |
8c21905b VS |
129 | wxLV_ITEM(LV_ITEMA &item) : m_buf(NULL), m_item(&item) {} |
130 | private: | |
131 | wxWC2WXbuf *m_buf; | |
2b5f62a0 | 132 | #endif // wxUSE_UNICODE/!wxUSE_UNICODE |
8c21905b VS |
133 | |
134 | LV_ITEM *m_item; | |
22f3361e VZ |
135 | |
136 | DECLARE_NO_COPY_CLASS(wxLV_ITEM) | |
8c21905b VS |
137 | }; |
138 | ||
7cf46fdb VZ |
139 | /////////////////////////////////////////////////////// |
140 | // Problem: | |
73d8c5fd RD |
141 | // The MSW version had problems with SetTextColour() et |
142 | // al as the wxListItemAttr's were stored keyed on the | |
143 | // item index. If a item was inserted anywhere but the end | |
144 | // of the list the the text attributes (colour etc) for | |
7cf46fdb | 145 | // the following items were out of sync. |
73d8c5fd | 146 | // |
7cf46fdb | 147 | // Solution: |
73d8c5fd RD |
148 | // Under MSW the only way to associate data with a List |
149 | // item independant of its position in the list is to | |
150 | // store a pointer to it in its lParam attribute. However | |
151 | // user programs are already using this (via the | |
7cf46fdb | 152 | // SetItemData() GetItemData() calls). |
73d8c5fd RD |
153 | // |
154 | // However what we can do is store a pointer to a | |
155 | // structure which contains the attributes we want *and* | |
7cf46fdb | 156 | // a lParam for the users data, e.g. |
73d8c5fd | 157 | // |
7cf46fdb VZ |
158 | // class wxListItemInternalData |
159 | // { | |
160 | // public: | |
73d8c5fd | 161 | // wxListItemAttr *attr; |
7cf46fdb VZ |
162 | // long lParam; // user data |
163 | // }; | |
73d8c5fd RD |
164 | // |
165 | // To conserve memory, a wxListItemInternalData is | |
166 | // only allocated for a LV_ITEM if text attributes or | |
7cf46fdb VZ |
167 | // user data(lparam) are being set. |
168 | ||
169 | ||
170 | // class wxListItemInternalData | |
171 | class wxListItemInternalData | |
172 | { | |
173 | public: | |
73d8c5fd | 174 | wxListItemAttr *attr; |
7cf46fdb VZ |
175 | LPARAM lParam; // user data |
176 | ||
177 | wxListItemInternalData() : attr(NULL), lParam(0) {} | |
178 | ~wxListItemInternalData() | |
179 | { | |
180 | if (attr) | |
181 | delete attr; | |
182 | }; | |
22f3361e VZ |
183 | |
184 | DECLARE_NO_COPY_CLASS(wxListItemInternalData) | |
7cf46fdb VZ |
185 | }; |
186 | ||
187 | // Get the internal data structure | |
6149de71 RD |
188 | static wxListItemInternalData *wxGetInternalData(HWND hwnd, long itemId); |
189 | static wxListItemInternalData *wxGetInternalData(wxListCtrl *ctl, long itemId); | |
190 | static wxListItemAttr *wxGetInternalDataAttr(wxListCtrl *ctl, long itemId); | |
191 | static void wxDeleteInternalData(wxListCtrl* ctl, long itemId); | |
7cf46fdb VZ |
192 | |
193 | ||
edccf428 | 194 | // ---------------------------------------------------------------------------- |
2e4df4bf | 195 | // events |
edccf428 VZ |
196 | // ---------------------------------------------------------------------------- |
197 | ||
2e4df4bf VZ |
198 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG) |
199 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG) | |
200 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT) | |
201 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT) | |
202 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM) | |
203 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS) | |
204 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO) | |
205 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO) | |
206 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED) | |
207 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED) | |
208 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN) | |
209 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM) | |
210 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK) | |
11358d39 VZ |
211 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK) |
212 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG) | |
213 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING) | |
214 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG) | |
2e4df4bf VZ |
215 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK) |
216 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK) | |
217 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED) | |
0ddefeb0 | 218 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED) |
614391dc | 219 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT) |
2e4df4bf | 220 | |
8f177c8e | 221 | IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl) |
bf9b6266 | 222 | IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl) |
8f177c8e | 223 | IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject) |
2bda0e17 | 224 | |
2d33aec9 VZ |
225 | IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent) |
226 | ||
2702ed5a JS |
227 | BEGIN_EVENT_TABLE(wxListCtrl, wxControl) |
228 | EVT_PAINT(wxListCtrl::OnPaint) | |
229 | END_EVENT_TABLE() | |
230 | ||
edccf428 VZ |
231 | // ============================================================================ |
232 | // implementation | |
233 | // ============================================================================ | |
234 | ||
235 | // ---------------------------------------------------------------------------- | |
236 | // wxListCtrl construction | |
237 | // ---------------------------------------------------------------------------- | |
238 | ||
bdc72a22 | 239 | void wxListCtrl::Init() |
2bda0e17 | 240 | { |
0b5efdc7 VZ |
241 | m_imageListNormal = NULL; |
242 | m_imageListSmall = NULL; | |
243 | m_imageListState = NULL; | |
2e12c11a | 244 | m_ownsImageListNormal = m_ownsImageListSmall = m_ownsImageListState = FALSE; |
0b5efdc7 | 245 | m_baseStyle = 0; |
2bda0e17 | 246 | m_colCount = 0; |
68c124a1 RD |
247 | m_count = 0; |
248 | m_ignoreChangeMessages = FALSE; | |
bbcdf8bc | 249 | m_textCtrl = NULL; |
7cf46fdb | 250 | m_AnyInternalData = FALSE; |
bdc72a22 | 251 | m_hasAnyAttr = FALSE; |
2bda0e17 KB |
252 | } |
253 | ||
0b5efdc7 VZ |
254 | bool wxListCtrl::Create(wxWindow *parent, |
255 | wxWindowID id, | |
256 | const wxPoint& pos, | |
257 | const wxSize& size, | |
258 | long style, | |
259 | const wxValidator& validator, | |
260 | const wxString& name) | |
2bda0e17 | 261 | { |
11b6a93b | 262 | #if wxUSE_VALIDATORS |
0b5efdc7 | 263 | SetValidator(validator); |
11b6a93b VZ |
264 | #endif // wxUSE_VALIDATORS |
265 | ||
0b5efdc7 | 266 | SetName(name); |
2bda0e17 | 267 | |
0b5efdc7 VZ |
268 | int x = pos.x; |
269 | int y = pos.y; | |
270 | int width = size.x; | |
271 | int height = size.y; | |
2bda0e17 | 272 | |
0b5efdc7 | 273 | m_windowStyle = style; |
2bda0e17 | 274 | |
0b5efdc7 | 275 | SetParent(parent); |
2bda0e17 | 276 | |
0b5efdc7 VZ |
277 | if (width <= 0) |
278 | width = 100; | |
279 | if (height <= 0) | |
280 | height = 30; | |
281 | if (x < 0) | |
282 | x = 0; | |
283 | if (y < 0) | |
284 | y = 0; | |
2bda0e17 | 285 | |
0b5efdc7 | 286 | m_windowId = (id == -1) ? NewControlId() : id; |
2bda0e17 | 287 | |
edccf428 VZ |
288 | DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP | |
289 | LVS_SHAREIMAGELISTS | LVS_SHOWSELALWAYS; | |
b0766406 JS |
290 | |
291 | if ( m_windowStyle & wxCLIP_SIBLINGS ) | |
292 | wstyle |= WS_CLIPSIBLINGS; | |
293 | ||
edccf428 VZ |
294 | if ( wxStyleHasBorder(m_windowStyle) ) |
295 | wstyle |= WS_BORDER; | |
296 | m_baseStyle = wstyle; | |
297 | ||
298 | if ( !DoCreateControl(x, y, width, height) ) | |
299 | return FALSE; | |
300 | ||
301 | if (parent) | |
302 | parent->AddChild(this); | |
303 | ||
304 | return TRUE; | |
305 | } | |
306 | ||
307 | bool wxListCtrl::DoCreateControl(int x, int y, int w, int h) | |
308 | { | |
309 | DWORD wstyle = m_baseStyle; | |
2bda0e17 | 310 | |
0b5efdc7 | 311 | bool want3D; |
edccf428 | 312 | WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D); |
2bda0e17 | 313 | |
0b5efdc7 VZ |
314 | // Even with extended styles, need to combine with WS_BORDER |
315 | // for them to look right. | |
edccf428 | 316 | if ( want3D ) |
0b5efdc7 | 317 | wstyle |= WS_BORDER; |
2bda0e17 | 318 | |
0b5efdc7 VZ |
319 | long oldStyle = 0; // Dummy |
320 | wstyle |= ConvertToMSWStyle(oldStyle, m_windowStyle); | |
2bda0e17 | 321 | |
0b5efdc7 VZ |
322 | // Create the ListView control. |
323 | m_hWnd = (WXHWND)CreateWindowEx(exStyle, | |
324 | WC_LISTVIEW, | |
223d09f6 | 325 | wxT(""), |
0b5efdc7 | 326 | wstyle, |
edccf428 VZ |
327 | x, y, w, h, |
328 | GetWinHwnd(GetParent()), | |
0b5efdc7 VZ |
329 | (HMENU)m_windowId, |
330 | wxGetInstance(), | |
331 | NULL); | |
f8352807 | 332 | |
edccf428 VZ |
333 | if ( !m_hWnd ) |
334 | { | |
f6bcfd97 | 335 | wxLogError(_("Can't create list control window, check that comctl32.dll is installed.")); |
0b5efdc7 VZ |
336 | |
337 | return FALSE; | |
338 | } | |
339 | ||
340 | // for comctl32.dll v 4.70+ we want to have this attribute because it's | |
341 | // prettier (and also because wxGTK does it like this) | |
225fe9d6 | 342 | if ( (wstyle & LVS_REPORT) && wxTheApp->GetComCtl32Version() >= 470 ) |
0b5efdc7 | 343 | { |
225fe9d6 VZ |
344 | ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE, |
345 | 0, LVS_EX_FULLROWSELECT); | |
0b5efdc7 | 346 | } |
f8352807 | 347 | |
a756f210 | 348 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); |
edccf428 | 349 | SetForegroundColour(GetParent()->GetForegroundColour()); |
2bda0e17 | 350 | |
edccf428 | 351 | SubclassWin(m_hWnd); |
2bda0e17 | 352 | |
0b5efdc7 | 353 | return TRUE; |
2bda0e17 KB |
354 | } |
355 | ||
edccf428 VZ |
356 | void wxListCtrl::UpdateStyle() |
357 | { | |
358 | if ( GetHWND() ) | |
359 | { | |
360 | // The new window view style | |
361 | long dummy; | |
362 | DWORD dwStyleNew = ConvertToMSWStyle(dummy, m_windowStyle); | |
363 | dwStyleNew |= m_baseStyle; | |
364 | ||
910484a6 | 365 | // Get the current window style. |
edccf428 VZ |
366 | DWORD dwStyleOld = ::GetWindowLong(GetHwnd(), GWL_STYLE); |
367 | ||
910484a6 | 368 | // Only set the window style if the view bits have changed. |
edccf428 VZ |
369 | if ( dwStyleOld != dwStyleNew ) |
370 | { | |
371 | ::SetWindowLong(GetHwnd(), GWL_STYLE, dwStyleNew); | |
372 | } | |
373 | } | |
374 | } | |
375 | ||
7cf46fdb | 376 | void wxListCtrl::FreeAllInternalData() |
2bda0e17 | 377 | { |
7cf46fdb | 378 | if (m_AnyInternalData) |
73d8c5fd | 379 | { |
7cf46fdb VZ |
380 | int n = GetItemCount(); |
381 | int i = 0; | |
6932a32c | 382 | |
68c124a1 | 383 | m_ignoreChangeMessages = TRUE; |
7cf46fdb | 384 | for (i = 0; i < n; i++) |
6149de71 | 385 | wxDeleteInternalData(this, i); |
3cfda0b7 | 386 | m_ignoreChangeMessages = FALSE; |
6149de71 | 387 | |
73d8c5fd RD |
388 | m_AnyInternalData = FALSE; |
389 | } | |
6932a32c | 390 | } |
d62228a6 | 391 | |
6932a32c VZ |
392 | wxListCtrl::~wxListCtrl() |
393 | { | |
7cf46fdb | 394 | FreeAllInternalData(); |
91b4c08d | 395 | |
d62228a6 | 396 | if ( m_textCtrl ) |
bbcdf8bc | 397 | { |
7bf1474a | 398 | m_textCtrl->UnsubclassWin(); |
f3076f9f | 399 | m_textCtrl->SetHWND(0); |
0b5efdc7 VZ |
400 | delete m_textCtrl; |
401 | m_textCtrl = NULL; | |
bbcdf8bc | 402 | } |
33ac7e6f | 403 | |
2e12c11a VS |
404 | if (m_ownsImageListNormal) delete m_imageListNormal; |
405 | if (m_ownsImageListSmall) delete m_imageListSmall; | |
406 | if (m_ownsImageListState) delete m_imageListState; | |
2bda0e17 KB |
407 | } |
408 | ||
edccf428 VZ |
409 | // ---------------------------------------------------------------------------- |
410 | // set/get/change style | |
411 | // ---------------------------------------------------------------------------- | |
412 | ||
2bda0e17 | 413 | // Add or remove a single window style |
debe6624 | 414 | void wxListCtrl::SetSingleStyle(long style, bool add) |
2bda0e17 | 415 | { |
0b5efdc7 | 416 | long flag = GetWindowStyleFlag(); |
2bda0e17 | 417 | |
0b5efdc7 | 418 | // Get rid of conflicting styles |
acb62b84 VZ |
419 | if ( add ) |
420 | { | |
0b5efdc7 | 421 | if ( style & wxLC_MASK_TYPE) |
edccf428 | 422 | flag = flag & ~wxLC_MASK_TYPE; |
0b5efdc7 | 423 | if ( style & wxLC_MASK_ALIGN ) |
edccf428 | 424 | flag = flag & ~wxLC_MASK_ALIGN; |
0b5efdc7 | 425 | if ( style & wxLC_MASK_SORT ) |
edccf428 | 426 | flag = flag & ~wxLC_MASK_SORT; |
acb62b84 | 427 | } |
2bda0e17 | 428 | |
0b5efdc7 VZ |
429 | if ( flag & style ) |
430 | { | |
431 | if ( !add ) | |
432 | flag -= style; | |
433 | } | |
434 | else | |
435 | { | |
436 | if ( add ) | |
437 | { | |
438 | flag |= style; | |
439 | } | |
440 | } | |
441 | ||
442 | m_windowStyle = flag; | |
2bda0e17 | 443 | |
edccf428 | 444 | UpdateStyle(); |
2bda0e17 KB |
445 | } |
446 | ||
447 | // Set the whole window style | |
debe6624 | 448 | void wxListCtrl::SetWindowStyleFlag(long flag) |
2bda0e17 | 449 | { |
0b5efdc7 | 450 | m_windowStyle = flag; |
2bda0e17 | 451 | |
edccf428 | 452 | UpdateStyle(); |
2bda0e17 KB |
453 | } |
454 | ||
0b5efdc7 VZ |
455 | // Can be just a single style, or a bitlist |
456 | long wxListCtrl::ConvertToMSWStyle(long& oldStyle, long style) const | |
2bda0e17 | 457 | { |
0b5efdc7 VZ |
458 | long wstyle = 0; |
459 | if ( style & wxLC_ICON ) | |
460 | { | |
461 | if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON ) | |
462 | oldStyle -= LVS_SMALLICON; | |
463 | if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT ) | |
464 | oldStyle -= LVS_REPORT; | |
465 | if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST ) | |
466 | oldStyle -= LVS_LIST; | |
467 | wstyle |= LVS_ICON; | |
468 | } | |
469 | ||
470 | if ( style & wxLC_SMALL_ICON ) | |
471 | { | |
472 | if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON ) | |
473 | oldStyle -= LVS_ICON; | |
474 | if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT ) | |
475 | oldStyle -= LVS_REPORT; | |
476 | if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST ) | |
477 | oldStyle -= LVS_LIST; | |
478 | wstyle |= LVS_SMALLICON; | |
479 | } | |
480 | ||
481 | if ( style & wxLC_LIST ) | |
482 | { | |
483 | if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON ) | |
484 | oldStyle -= LVS_ICON; | |
485 | if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT ) | |
486 | oldStyle -= LVS_REPORT; | |
487 | if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON ) | |
488 | oldStyle -= LVS_SMALLICON; | |
489 | wstyle |= LVS_LIST; | |
490 | } | |
2bda0e17 | 491 | |
0b5efdc7 VZ |
492 | if ( style & wxLC_REPORT ) |
493 | { | |
494 | if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON ) | |
495 | oldStyle -= LVS_ICON; | |
496 | if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST ) | |
497 | oldStyle -= LVS_LIST; | |
498 | if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON ) | |
499 | oldStyle -= LVS_SMALLICON; | |
500 | ||
501 | wstyle |= LVS_REPORT; | |
502 | } | |
2bda0e17 | 503 | |
0b5efdc7 VZ |
504 | if ( style & wxLC_ALIGN_LEFT ) |
505 | { | |
506 | if ( oldStyle & LVS_ALIGNTOP ) | |
507 | oldStyle -= LVS_ALIGNTOP; | |
508 | wstyle |= LVS_ALIGNLEFT; | |
509 | } | |
2bda0e17 | 510 | |
0b5efdc7 VZ |
511 | if ( style & wxLC_ALIGN_TOP ) |
512 | { | |
513 | if ( oldStyle & LVS_ALIGNLEFT ) | |
514 | oldStyle -= LVS_ALIGNLEFT; | |
515 | wstyle |= LVS_ALIGNTOP; | |
516 | } | |
2bda0e17 | 517 | |
0b5efdc7 VZ |
518 | if ( style & wxLC_AUTOARRANGE ) |
519 | wstyle |= LVS_AUTOARRANGE; | |
2bda0e17 | 520 | |
0b5efdc7 VZ |
521 | if ( style & wxLC_NO_SORT_HEADER ) |
522 | wstyle |= LVS_NOSORTHEADER; | |
2bda0e17 | 523 | |
0b5efdc7 VZ |
524 | if ( style & wxLC_NO_HEADER ) |
525 | wstyle |= LVS_NOCOLUMNHEADER; | |
526 | ||
527 | if ( style & wxLC_EDIT_LABELS ) | |
528 | wstyle |= LVS_EDITLABELS; | |
529 | ||
530 | if ( style & wxLC_SINGLE_SEL ) | |
531 | wstyle |= LVS_SINGLESEL; | |
532 | ||
533 | if ( style & wxLC_SORT_ASCENDING ) | |
534 | { | |
535 | if ( oldStyle & LVS_SORTDESCENDING ) | |
536 | oldStyle -= LVS_SORTDESCENDING; | |
537 | wstyle |= LVS_SORTASCENDING; | |
538 | } | |
539 | ||
540 | if ( style & wxLC_SORT_DESCENDING ) | |
541 | { | |
542 | if ( oldStyle & LVS_SORTASCENDING ) | |
543 | oldStyle -= LVS_SORTASCENDING; | |
544 | wstyle |= LVS_SORTDESCENDING; | |
545 | } | |
546 | ||
bf9b6266 | 547 | #if !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) ) |
98ec9dbe VZ |
548 | if ( style & wxLC_VIRTUAL ) |
549 | { | |
30a72e62 VZ |
550 | int ver = wxTheApp->GetComCtl32Version(); |
551 | if ( ver < 470 ) | |
552 | { | |
bf9b6266 | 553 | 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 |
554 | ver / 100, ver % 100); |
555 | } | |
556 | ||
98ec9dbe VZ |
557 | wstyle |= LVS_OWNERDATA; |
558 | } | |
bf9b6266 | 559 | #endif |
98ec9dbe | 560 | |
0b5efdc7 | 561 | return wstyle; |
2bda0e17 KB |
562 | } |
563 | ||
edccf428 VZ |
564 | // ---------------------------------------------------------------------------- |
565 | // accessors | |
566 | // ---------------------------------------------------------------------------- | |
567 | ||
91b4c08d VZ |
568 | // Sets the foreground, i.e. text, colour |
569 | bool wxListCtrl::SetForegroundColour(const wxColour& col) | |
570 | { | |
571 | if ( !wxWindow::SetForegroundColour(col) ) | |
572 | return FALSE; | |
573 | ||
574 | ListView_SetTextColor(GetHwnd(), wxColourToRGB(col)); | |
575 | ||
576 | return TRUE; | |
577 | } | |
578 | ||
579 | // Sets the background colour | |
cc2b7472 | 580 | bool wxListCtrl::SetBackgroundColour(const wxColour& col) |
2bda0e17 | 581 | { |
cc2b7472 VZ |
582 | if ( !wxWindow::SetBackgroundColour(col) ) |
583 | return FALSE; | |
2bda0e17 | 584 | |
91b4c08d VZ |
585 | // we set the same colour for both the "empty" background and the items |
586 | // background | |
587 | COLORREF color = wxColourToRGB(col); | |
588 | ListView_SetBkColor(GetHwnd(), color); | |
589 | ListView_SetTextBkColor(GetHwnd(), color); | |
cc2b7472 VZ |
590 | |
591 | return TRUE; | |
2bda0e17 KB |
592 | } |
593 | ||
594 | // Gets information about this column | |
debe6624 | 595 | bool wxListCtrl::GetColumn(int col, wxListItem& item) const |
2bda0e17 | 596 | { |
0b5efdc7 | 597 | LV_COLUMN lvCol; |
6f806543 | 598 | wxZeroMemory(lvCol); |
0b5efdc7 | 599 | |
37094564 RD |
600 | lvCol.mask = LVCF_WIDTH; |
601 | ||
0b5efdc7 VZ |
602 | if ( item.m_mask & wxLIST_MASK_TEXT ) |
603 | { | |
604 | lvCol.mask |= LVCF_TEXT; | |
837e5743 | 605 | lvCol.pszText = new wxChar[513]; |
0b5efdc7 VZ |
606 | lvCol.cchTextMax = 512; |
607 | } | |
608 | ||
37094564 RD |
609 | if ( item.m_mask & wxLIST_MASK_FORMAT ) |
610 | { | |
611 | lvCol.mask |= LVCF_FMT; | |
612 | } | |
613 | ||
614 | if ( item.m_mask & wxLIST_MASK_IMAGE ) | |
615 | { | |
616 | lvCol.mask |= LVCF_IMAGE; | |
617 | } | |
618 | ||
0b190ffc | 619 | bool success = ListView_GetColumn(GetHwnd(), col, &lvCol) != 0; |
0b5efdc7 VZ |
620 | |
621 | // item.m_subItem = lvCol.iSubItem; | |
622 | item.m_width = lvCol.cx; | |
623 | ||
624 | if ( (item.m_mask & wxLIST_MASK_TEXT) && lvCol.pszText ) | |
625 | { | |
626 | item.m_text = lvCol.pszText; | |
627 | delete[] lvCol.pszText; | |
628 | } | |
629 | ||
630 | if ( item.m_mask & wxLIST_MASK_FORMAT ) | |
631 | { | |
0b190ffc RD |
632 | switch (lvCol.fmt & LVCFMT_JUSTIFYMASK) { |
633 | case LVCFMT_LEFT: | |
634 | item.m_format = wxLIST_FORMAT_LEFT; | |
635 | break; | |
636 | case LVCFMT_RIGHT: | |
637 | item.m_format = wxLIST_FORMAT_RIGHT; | |
638 | break; | |
639 | case LVCFMT_CENTER: | |
640 | item.m_format = wxLIST_FORMAT_CENTRE; | |
641 | break; | |
642 | default: | |
643 | item.m_format = -1; // Unknown? | |
644 | break; | |
645 | } | |
2bda0e17 KB |
646 | } |
647 | ||
8ac67aa1 | 648 | #if _WIN32_IE >= 0x0300 |
37094564 RD |
649 | if ( item.m_mask & wxLIST_MASK_IMAGE ) |
650 | { | |
651 | item.m_image = lvCol.iImage; | |
652 | } | |
8ac67aa1 | 653 | #endif |
37094564 | 654 | |
0b5efdc7 | 655 | return success; |
2bda0e17 KB |
656 | } |
657 | ||
658 | // Sets information about this column | |
debe6624 | 659 | bool wxListCtrl::SetColumn(int col, wxListItem& item) |
2bda0e17 | 660 | { |
0b5efdc7 | 661 | LV_COLUMN lvCol; |
6f806543 | 662 | wxConvertToMSWListCol(col, item, lvCol); |
0b5efdc7 | 663 | |
6f806543 | 664 | return ListView_SetColumn(GetHwnd(), col, &lvCol) != 0; |
2bda0e17 KB |
665 | } |
666 | ||
667 | // Gets the column width | |
debe6624 | 668 | int wxListCtrl::GetColumnWidth(int col) const |
2bda0e17 | 669 | { |
edccf428 | 670 | return ListView_GetColumnWidth(GetHwnd(), col); |
2bda0e17 KB |
671 | } |
672 | ||
673 | // Sets the column width | |
debe6624 | 674 | bool wxListCtrl::SetColumnWidth(int col, int width) |
2bda0e17 | 675 | { |
0b5efdc7 VZ |
676 | int col2 = col; |
677 | if ( m_windowStyle & wxLC_LIST ) | |
678 | col2 = -1; | |
2bda0e17 | 679 | |
0b5efdc7 VZ |
680 | int width2 = width; |
681 | if ( width2 == wxLIST_AUTOSIZE) | |
682 | width2 = LVSCW_AUTOSIZE; | |
683 | else if ( width2 == wxLIST_AUTOSIZE_USEHEADER) | |
684 | width2 = LVSCW_AUTOSIZE_USEHEADER; | |
2bda0e17 | 685 | |
6f806543 | 686 | return ListView_SetColumnWidth(GetHwnd(), col2, width2) != 0; |
2bda0e17 KB |
687 | } |
688 | ||
689 | // Gets the number of items that can fit vertically in the | |
690 | // visible area of the list control (list or report view) | |
691 | // or the total number of items in the list control (icon | |
692 | // or small icon view) | |
c42404a5 | 693 | int wxListCtrl::GetCountPerPage() const |
2bda0e17 | 694 | { |
edccf428 | 695 | return ListView_GetCountPerPage(GetHwnd()); |
2bda0e17 KB |
696 | } |
697 | ||
698 | // Gets the edit control for editing labels. | |
c42404a5 | 699 | wxTextCtrl* wxListCtrl::GetEditControl() const |
2bda0e17 | 700 | { |
bbcdf8bc | 701 | return m_textCtrl; |
2bda0e17 KB |
702 | } |
703 | ||
704 | // Gets information about the item | |
705 | bool wxListCtrl::GetItem(wxListItem& info) const | |
706 | { | |
0b5efdc7 | 707 | LV_ITEM lvItem; |
11c7d5b6 | 708 | wxZeroMemory(lvItem); |
2bda0e17 | 709 | |
0b5efdc7 | 710 | lvItem.iItem = info.m_itemId; |
fc5a93cd | 711 | lvItem.iSubItem = info.m_col; |
0b5efdc7 VZ |
712 | |
713 | if ( info.m_mask & wxLIST_MASK_TEXT ) | |
714 | { | |
715 | lvItem.mask |= LVIF_TEXT; | |
837e5743 | 716 | lvItem.pszText = new wxChar[513]; |
0b5efdc7 VZ |
717 | lvItem.cchTextMax = 512; |
718 | } | |
719 | else | |
720 | { | |
721 | lvItem.pszText = NULL; | |
722 | } | |
723 | ||
724 | if (info.m_mask & wxLIST_MASK_DATA) | |
edccf428 | 725 | lvItem.mask |= LVIF_PARAM; |
0b5efdc7 | 726 | |
2189c644 JS |
727 | if (info.m_mask & wxLIST_MASK_IMAGE) |
728 | lvItem.mask |= LVIF_IMAGE; | |
729 | ||
0b5efdc7 VZ |
730 | if ( info.m_mask & wxLIST_MASK_STATE ) |
731 | { | |
732 | lvItem.mask |= LVIF_STATE; | |
733 | // the other bits are hardly interesting anyhow | |
734 | lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED; | |
735 | } | |
736 | ||
737 | bool success = ListView_GetItem((HWND)GetHWND(), &lvItem) != 0; | |
738 | if ( !success ) | |
739 | { | |
740 | wxLogError(_("Couldn't retrieve information about list control item %d."), | |
741 | lvItem.iItem); | |
742 | } | |
743 | else | |
744 | { | |
dccde0c0 VZ |
745 | // give NULL as hwnd as we already have everything we need |
746 | wxConvertFromMSWListItem(NULL, info, lvItem); | |
0b5efdc7 VZ |
747 | } |
748 | ||
749 | if (lvItem.pszText) | |
750 | delete[] lvItem.pszText; | |
751 | ||
752 | return success; | |
2bda0e17 KB |
753 | } |
754 | ||
755 | // Sets information about the item | |
756 | bool wxListCtrl::SetItem(wxListItem& info) | |
757 | { | |
0b5efdc7 | 758 | LV_ITEM item; |
2bda0e17 | 759 | wxConvertToMSWListItem(this, info, item); |
bdc72a22 | 760 | |
7cf46fdb VZ |
761 | // we never update the lParam if it contains our pointer |
762 | // to the wxListItemInternalData structure | |
763 | item.mask &= ~LVIF_PARAM; | |
764 | ||
765 | // check if setting attributes or lParam | |
766 | if (info.HasAttributes() || (info.m_mask & wxLIST_MASK_DATA)) | |
767 | { | |
768 | // get internal item data | |
769 | // perhaps a cache here ? | |
6149de71 | 770 | wxListItemInternalData *data = wxGetInternalData(this, info.m_itemId); |
73d8c5fd | 771 | |
7cf46fdb VZ |
772 | if (! data) |
773 | { | |
774 | // need to set it | |
775 | m_AnyInternalData = TRUE; | |
776 | data = new wxListItemInternalData(); | |
777 | item.lParam = (LPARAM) data; | |
778 | item.mask |= LVIF_PARAM; | |
779 | }; | |
780 | ||
781 | ||
782 | // user data | |
783 | if (info.m_mask & wxLIST_MASK_DATA) | |
784 | data->lParam = info.m_data; | |
785 | ||
786 | // attributes | |
787 | if (info.HasAttributes()) | |
788 | { | |
789 | if (data->attr) | |
790 | *data->attr = *info.GetAttributes(); | |
791 | else | |
792 | data->attr = new wxListItemAttr(*info.GetAttributes()); | |
793 | }; | |
794 | }; | |
795 | ||
796 | ||
2d33aec9 VZ |
797 | // we could be changing only the attribute in which case we don't need to |
798 | // call ListView_SetItem() at all | |
799 | if ( item.mask ) | |
bdc72a22 | 800 | { |
2d33aec9 VZ |
801 | item.cchTextMax = 0; |
802 | if ( !ListView_SetItem(GetHwnd(), &item) ) | |
803 | { | |
804 | wxLogDebug(_T("ListView_SetItem() failed")); | |
2702ed5a | 805 | |
2d33aec9 VZ |
806 | return FALSE; |
807 | } | |
233d0295 | 808 | } |
2702ed5a | 809 | |
233d0295 VZ |
810 | // we need to update the item immediately to show the new image |
811 | bool updateNow = (info.m_mask & wxLIST_MASK_IMAGE) != 0; | |
2702ed5a | 812 | |
233d0295 VZ |
813 | // check whether it has any custom attributes |
814 | if ( info.HasAttributes() ) | |
815 | { | |
bdc72a22 | 816 | m_hasAnyAttr = TRUE; |
233d0295 VZ |
817 | |
818 | // if the colour has changed, we must redraw the item | |
819 | updateNow = TRUE; | |
bdc72a22 | 820 | } |
bdc72a22 | 821 | |
233d0295 | 822 | if ( updateNow ) |
7cc98b3e | 823 | { |
233d0295 | 824 | // we need this to make the change visible right now |
2d33aec9 | 825 | RefreshItem(item.iItem); |
7cc98b3e VZ |
826 | } |
827 | ||
233d0295 | 828 | return TRUE; |
2bda0e17 KB |
829 | } |
830 | ||
debe6624 | 831 | long wxListCtrl::SetItem(long index, int col, const wxString& label, int imageId) |
2bda0e17 | 832 | { |
0b5efdc7 VZ |
833 | wxListItem info; |
834 | info.m_text = label; | |
835 | info.m_mask = wxLIST_MASK_TEXT; | |
836 | info.m_itemId = index; | |
837 | info.m_col = col; | |
838 | if ( imageId > -1 ) | |
839 | { | |
840 | info.m_image = imageId; | |
841 | info.m_mask |= wxLIST_MASK_IMAGE; | |
842 | } | |
843 | return SetItem(info); | |
2bda0e17 KB |
844 | } |
845 | ||
846 | ||
847 | // Gets the item state | |
debe6624 | 848 | int wxListCtrl::GetItemState(long item, long stateMask) const |
2bda0e17 | 849 | { |
0b5efdc7 | 850 | wxListItem info; |
2bda0e17 | 851 | |
edccf428 | 852 | info.m_mask = wxLIST_MASK_STATE; |
0b5efdc7 VZ |
853 | info.m_stateMask = stateMask; |
854 | info.m_itemId = item; | |
2bda0e17 | 855 | |
0b5efdc7 VZ |
856 | if (!GetItem(info)) |
857 | return 0; | |
2bda0e17 | 858 | |
0b5efdc7 | 859 | return info.m_state; |
2bda0e17 KB |
860 | } |
861 | ||
862 | // Sets the item state | |
debe6624 | 863 | bool wxListCtrl::SetItemState(long item, long state, long stateMask) |
2bda0e17 | 864 | { |
8dff2b5c VZ |
865 | // NB: don't use SetItem() here as it doesn't work with the virtual list |
866 | // controls | |
867 | LV_ITEM lvItem; | |
868 | wxZeroMemory(lvItem); | |
2bda0e17 | 869 | |
8dff2b5c | 870 | wxConvertToMSWFlags(state, stateMask, lvItem); |
2bda0e17 | 871 | |
2d33aec9 | 872 | // for the virtual list controls we need to refresh the previously focused |
ad9f477d VZ |
873 | // item manually when changing focus without changing selection |
874 | // programmatically because otherwise it keeps its focus rectangle until | |
875 | // next repaint (yet another comctl32 bug) | |
2d33aec9 VZ |
876 | long focusOld; |
877 | if ( IsVirtual() && | |
878 | (stateMask & wxLIST_STATE_FOCUSED) && | |
879 | (state & wxLIST_STATE_FOCUSED) ) | |
880 | { | |
881 | focusOld = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED); | |
882 | } | |
883 | else | |
884 | { | |
885 | focusOld = -1; | |
886 | } | |
887 | ||
8dff2b5c VZ |
888 | if ( !::SendMessage(GetHwnd(), LVM_SETITEMSTATE, |
889 | (WPARAM)item, (LPARAM)&lvItem) ) | |
890 | { | |
891 | wxLogLastError(_T("ListView_SetItemState")); | |
892 | ||
893 | return FALSE; | |
894 | } | |
895 | ||
2d33aec9 VZ |
896 | if ( focusOld != -1 ) |
897 | { | |
ad9f477d VZ |
898 | // no need to refresh the item if it was previously selected, it would |
899 | // only result in annoying flicker | |
900 | if ( !(GetItemState(focusOld, | |
901 | wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED) ) | |
902 | { | |
903 | RefreshItem(focusOld); | |
904 | } | |
2d33aec9 VZ |
905 | } |
906 | ||
8dff2b5c | 907 | return TRUE; |
2bda0e17 KB |
908 | } |
909 | ||
910 | // Sets the item image | |
33ac7e6f | 911 | bool wxListCtrl::SetItemImage(long item, int image, int WXUNUSED(selImage)) |
2bda0e17 | 912 | { |
0b5efdc7 | 913 | wxListItem info; |
2bda0e17 | 914 | |
edccf428 | 915 | info.m_mask = wxLIST_MASK_IMAGE; |
0b5efdc7 VZ |
916 | info.m_image = image; |
917 | info.m_itemId = item; | |
2bda0e17 | 918 | |
0b5efdc7 | 919 | return SetItem(info); |
2bda0e17 KB |
920 | } |
921 | ||
922 | // Gets the item text | |
debe6624 | 923 | wxString wxListCtrl::GetItemText(long item) const |
2bda0e17 | 924 | { |
0b5efdc7 | 925 | wxListItem info; |
2bda0e17 | 926 | |
edccf428 | 927 | info.m_mask = wxLIST_MASK_TEXT; |
0b5efdc7 | 928 | info.m_itemId = item; |
2bda0e17 | 929 | |
0b5efdc7 | 930 | if (!GetItem(info)) |
2b5f62a0 | 931 | return wxEmptyString; |
0b5efdc7 | 932 | return info.m_text; |
2bda0e17 KB |
933 | } |
934 | ||
935 | // Sets the item text | |
debe6624 | 936 | void wxListCtrl::SetItemText(long item, const wxString& str) |
2bda0e17 | 937 | { |
0b5efdc7 | 938 | wxListItem info; |
2bda0e17 | 939 | |
edccf428 | 940 | info.m_mask = wxLIST_MASK_TEXT; |
0b5efdc7 VZ |
941 | info.m_itemId = item; |
942 | info.m_text = str; | |
2bda0e17 | 943 | |
0b5efdc7 | 944 | SetItem(info); |
2bda0e17 KB |
945 | } |
946 | ||
947 | // Gets the item data | |
debe6624 | 948 | long wxListCtrl::GetItemData(long item) const |
2bda0e17 | 949 | { |
0b5efdc7 | 950 | wxListItem info; |
2bda0e17 | 951 | |
edccf428 | 952 | info.m_mask = wxLIST_MASK_DATA; |
0b5efdc7 | 953 | info.m_itemId = item; |
2bda0e17 | 954 | |
0b5efdc7 VZ |
955 | if (!GetItem(info)) |
956 | return 0; | |
957 | return info.m_data; | |
2bda0e17 KB |
958 | } |
959 | ||
960 | // Sets the item data | |
debe6624 | 961 | bool wxListCtrl::SetItemData(long item, long data) |
2bda0e17 | 962 | { |
0b5efdc7 | 963 | wxListItem info; |
2bda0e17 | 964 | |
edccf428 | 965 | info.m_mask = wxLIST_MASK_DATA; |
0b5efdc7 VZ |
966 | info.m_itemId = item; |
967 | info.m_data = data; | |
2bda0e17 | 968 | |
0b5efdc7 | 969 | return SetItem(info); |
2bda0e17 KB |
970 | } |
971 | ||
972 | // Gets the item rectangle | |
16e93305 | 973 | bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const |
2bda0e17 | 974 | { |
2d33aec9 | 975 | RECT rectWin; |
2bda0e17 | 976 | |
2d33aec9 | 977 | int codeWin; |
0b5efdc7 | 978 | if ( code == wxLIST_RECT_BOUNDS ) |
2d33aec9 | 979 | codeWin = LVIR_BOUNDS; |
0b5efdc7 | 980 | else if ( code == wxLIST_RECT_ICON ) |
2d33aec9 | 981 | codeWin = LVIR_ICON; |
0b5efdc7 | 982 | else if ( code == wxLIST_RECT_LABEL ) |
2d33aec9 VZ |
983 | codeWin = LVIR_LABEL; |
984 | else | |
985 | { | |
986 | wxFAIL_MSG( _T("incorrect code in GetItemRect()") ); | |
987 | ||
988 | codeWin = LVIR_BOUNDS; | |
989 | } | |
2bda0e17 | 990 | |
2d33aec9 | 991 | bool success = ListView_GetItemRect(GetHwnd(), (int) item, &rectWin, codeWin) != 0; |
2bda0e17 | 992 | |
2d33aec9 VZ |
993 | rect.x = rectWin.left; |
994 | rect.y = rectWin.top; | |
995 | rect.width = rectWin.right - rectWin.left; | |
996 | rect.height = rectWin.bottom - rectWin.top; | |
997 | ||
0b5efdc7 | 998 | return success; |
2bda0e17 KB |
999 | } |
1000 | ||
1001 | // Gets the item position | |
debe6624 | 1002 | bool wxListCtrl::GetItemPosition(long item, wxPoint& pos) const |
2bda0e17 | 1003 | { |
0b5efdc7 | 1004 | POINT pt; |
2bda0e17 | 1005 | |
edccf428 | 1006 | bool success = (ListView_GetItemPosition(GetHwnd(), (int) item, &pt) != 0); |
2bda0e17 | 1007 | |
0b5efdc7 VZ |
1008 | pos.x = pt.x; pos.y = pt.y; |
1009 | return success; | |
2bda0e17 KB |
1010 | } |
1011 | ||
1012 | // Sets the item position. | |
debe6624 | 1013 | bool wxListCtrl::SetItemPosition(long item, const wxPoint& pos) |
2bda0e17 | 1014 | { |
edccf428 | 1015 | return (ListView_SetItemPosition(GetHwnd(), (int) item, pos.x, pos.y) != 0); |
2bda0e17 KB |
1016 | } |
1017 | ||
1018 | // Gets the number of items in the list control | |
c42404a5 | 1019 | int wxListCtrl::GetItemCount() const |
2bda0e17 | 1020 | { |
68c124a1 | 1021 | return m_count; |
2bda0e17 KB |
1022 | } |
1023 | ||
1024 | // Retrieves the spacing between icons in pixels. | |
1025 | // If small is TRUE, gets the spacing for the small icon | |
1026 | // view, otherwise the large icon view. | |
1027 | int wxListCtrl::GetItemSpacing(bool isSmall) const | |
1028 | { | |
edccf428 | 1029 | return ListView_GetItemSpacing(GetHwnd(), (BOOL) isSmall); |
2bda0e17 KB |
1030 | } |
1031 | ||
5b98eb2f RL |
1032 | void wxListCtrl::SetItemTextColour( long item, const wxColour &col ) |
1033 | { | |
1034 | wxListItem info; | |
1035 | info.m_itemId = item; | |
1036 | info.SetTextColour( col ); | |
1037 | SetItem( info ); | |
1038 | } | |
1039 | ||
1040 | wxColour wxListCtrl::GetItemTextColour( long item ) const | |
1041 | { | |
1042 | wxListItem info; | |
1043 | info.m_itemId = item; | |
1044 | GetItem( info ); | |
1045 | return info.GetTextColour(); | |
1046 | } | |
1047 | ||
1048 | void wxListCtrl::SetItemBackgroundColour( long item, const wxColour &col ) | |
1049 | { | |
1050 | wxListItem info; | |
1051 | info.m_itemId = item; | |
1052 | info.SetBackgroundColour( col ); | |
1053 | SetItem( info ); | |
1054 | } | |
1055 | ||
1056 | wxColour wxListCtrl::GetItemBackgroundColour( long item ) const | |
1057 | { | |
1058 | wxListItem info; | |
1059 | info.m_itemId = item; | |
1060 | GetItem( info ); | |
1061 | return info.GetBackgroundColour(); | |
1062 | } | |
1063 | ||
2bda0e17 | 1064 | // Gets the number of selected items in the list control |
c42404a5 | 1065 | int wxListCtrl::GetSelectedItemCount() const |
2bda0e17 | 1066 | { |
edccf428 | 1067 | return ListView_GetSelectedCount(GetHwnd()); |
2bda0e17 KB |
1068 | } |
1069 | ||
1070 | // Gets the text colour of the listview | |
c42404a5 | 1071 | wxColour wxListCtrl::GetTextColour() const |
2bda0e17 | 1072 | { |
edccf428 | 1073 | COLORREF ref = ListView_GetTextColor(GetHwnd()); |
0b5efdc7 VZ |
1074 | wxColour col(GetRValue(ref), GetGValue(ref), GetBValue(ref)); |
1075 | return col; | |
2bda0e17 KB |
1076 | } |
1077 | ||
1078 | // Sets the text colour of the listview | |
1079 | void wxListCtrl::SetTextColour(const wxColour& col) | |
1080 | { | |
910484a6 | 1081 | ListView_SetTextColor(GetHwnd(), PALETTERGB(col.Red(), col.Green(), col.Blue())); |
2bda0e17 KB |
1082 | } |
1083 | ||
1084 | // Gets the index of the topmost visible item when in | |
1085 | // list or report view | |
c42404a5 | 1086 | long wxListCtrl::GetTopItem() const |
2bda0e17 | 1087 | { |
edccf428 | 1088 | return (long) ListView_GetTopIndex(GetHwnd()); |
2bda0e17 KB |
1089 | } |
1090 | ||
1091 | // Searches for an item, starting from 'item'. | |
1092 | // 'geometry' is one of | |
1093 | // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT. | |
1094 | // 'state' is a state bit flag, one or more of | |
1095 | // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT. | |
1096 | // item can be -1 to find the first item that matches the | |
1097 | // specified flags. | |
1098 | // Returns the item or -1 if unsuccessful. | |
debe6624 | 1099 | long wxListCtrl::GetNextItem(long item, int geom, int state) const |
2bda0e17 | 1100 | { |
0b5efdc7 | 1101 | long flags = 0; |
2bda0e17 | 1102 | |
0b5efdc7 VZ |
1103 | if ( geom == wxLIST_NEXT_ABOVE ) |
1104 | flags |= LVNI_ABOVE; | |
1105 | if ( geom == wxLIST_NEXT_ALL ) | |
1106 | flags |= LVNI_ALL; | |
1107 | if ( geom == wxLIST_NEXT_BELOW ) | |
1108 | flags |= LVNI_BELOW; | |
1109 | if ( geom == wxLIST_NEXT_LEFT ) | |
1110 | flags |= LVNI_TOLEFT; | |
1111 | if ( geom == wxLIST_NEXT_RIGHT ) | |
1112 | flags |= LVNI_TORIGHT; | |
2bda0e17 | 1113 | |
0b5efdc7 VZ |
1114 | if ( state & wxLIST_STATE_CUT ) |
1115 | flags |= LVNI_CUT; | |
1116 | if ( state & wxLIST_STATE_DROPHILITED ) | |
1117 | flags |= LVNI_DROPHILITED; | |
1118 | if ( state & wxLIST_STATE_FOCUSED ) | |
1119 | flags |= LVNI_FOCUSED; | |
1120 | if ( state & wxLIST_STATE_SELECTED ) | |
1121 | flags |= LVNI_SELECTED; | |
2bda0e17 | 1122 | |
edccf428 | 1123 | return (long) ListView_GetNextItem(GetHwnd(), item, flags); |
2bda0e17 KB |
1124 | } |
1125 | ||
1126 | ||
debe6624 | 1127 | wxImageList *wxListCtrl::GetImageList(int which) const |
2bda0e17 | 1128 | { |
0b5efdc7 | 1129 | if ( which == wxIMAGE_LIST_NORMAL ) |
2bda0e17 | 1130 | { |
0b5efdc7 VZ |
1131 | return m_imageListNormal; |
1132 | } | |
1133 | else if ( which == wxIMAGE_LIST_SMALL ) | |
2bda0e17 | 1134 | { |
0b5efdc7 VZ |
1135 | return m_imageListSmall; |
1136 | } | |
1137 | else if ( which == wxIMAGE_LIST_STATE ) | |
2bda0e17 | 1138 | { |
0b5efdc7 VZ |
1139 | return m_imageListState; |
1140 | } | |
1141 | return NULL; | |
2bda0e17 KB |
1142 | } |
1143 | ||
debe6624 | 1144 | void wxListCtrl::SetImageList(wxImageList *imageList, int which) |
2bda0e17 | 1145 | { |
0b5efdc7 VZ |
1146 | int flags = 0; |
1147 | if ( which == wxIMAGE_LIST_NORMAL ) | |
2bda0e17 | 1148 | { |
0b5efdc7 | 1149 | flags = LVSIL_NORMAL; |
2e12c11a | 1150 | if (m_ownsImageListNormal) delete m_imageListNormal; |
0b5efdc7 | 1151 | m_imageListNormal = imageList; |
2e12c11a | 1152 | m_ownsImageListNormal = FALSE; |
0b5efdc7 VZ |
1153 | } |
1154 | else if ( which == wxIMAGE_LIST_SMALL ) | |
2bda0e17 | 1155 | { |
0b5efdc7 | 1156 | flags = LVSIL_SMALL; |
2e12c11a | 1157 | if (m_ownsImageListSmall) delete m_imageListSmall; |
0b5efdc7 | 1158 | m_imageListSmall = imageList; |
2e12c11a | 1159 | m_ownsImageListSmall = FALSE; |
0b5efdc7 VZ |
1160 | } |
1161 | else if ( which == wxIMAGE_LIST_STATE ) | |
2bda0e17 | 1162 | { |
0b5efdc7 | 1163 | flags = LVSIL_STATE; |
2e12c11a | 1164 | if (m_ownsImageListState) delete m_imageListState; |
0b5efdc7 | 1165 | m_imageListState = imageList; |
2e12c11a | 1166 | m_ownsImageListState = FALSE; |
0b5efdc7 | 1167 | } |
edccf428 | 1168 | ListView_SetImageList(GetHwnd(), (HIMAGELIST) imageList ? imageList->GetHIMAGELIST() : 0, flags); |
2bda0e17 KB |
1169 | } |
1170 | ||
2e12c11a VS |
1171 | void wxListCtrl::AssignImageList(wxImageList *imageList, int which) |
1172 | { | |
1173 | SetImageList(imageList, which); | |
1174 | if ( which == wxIMAGE_LIST_NORMAL ) | |
1175 | m_ownsImageListNormal = TRUE; | |
1176 | else if ( which == wxIMAGE_LIST_SMALL ) | |
1177 | m_ownsImageListSmall = TRUE; | |
1178 | else if ( which == wxIMAGE_LIST_STATE ) | |
1179 | m_ownsImageListState = TRUE; | |
1180 | } | |
1181 | ||
edccf428 | 1182 | // ---------------------------------------------------------------------------- |
2bda0e17 | 1183 | // Operations |
edccf428 | 1184 | // ---------------------------------------------------------------------------- |
2bda0e17 KB |
1185 | |
1186 | // Arranges the items | |
debe6624 | 1187 | bool wxListCtrl::Arrange(int flag) |
2bda0e17 | 1188 | { |
0b5efdc7 VZ |
1189 | UINT code = 0; |
1190 | if ( flag == wxLIST_ALIGN_LEFT ) | |
1191 | code = LVA_ALIGNLEFT; | |
1192 | else if ( flag == wxLIST_ALIGN_TOP ) | |
1193 | code = LVA_ALIGNTOP; | |
1194 | else if ( flag == wxLIST_ALIGN_DEFAULT ) | |
1195 | code = LVA_DEFAULT; | |
1196 | else if ( flag == wxLIST_ALIGN_SNAP_TO_GRID ) | |
1197 | code = LVA_SNAPTOGRID; | |
2bda0e17 | 1198 | |
edccf428 | 1199 | return (ListView_Arrange(GetHwnd(), code) != 0); |
2bda0e17 KB |
1200 | } |
1201 | ||
1202 | // Deletes an item | |
debe6624 | 1203 | bool wxListCtrl::DeleteItem(long item) |
2bda0e17 | 1204 | { |
2e9f62da VZ |
1205 | if ( !ListView_DeleteItem(GetHwnd(), (int) item) ) |
1206 | { | |
1207 | wxLogLastError(_T("ListView_DeleteItem")); | |
1208 | return FALSE; | |
1209 | } | |
1210 | ||
68c124a1 RD |
1211 | m_count -= 1; |
1212 | wxASSERT_MSG( m_count == ListView_GetItemCount(GetHwnd()), | |
1213 | wxT("m_count should match ListView_GetItemCount")); | |
1214 | ||
2e9f62da VZ |
1215 | // the virtual list control doesn't refresh itself correctly, help it |
1216 | if ( IsVirtual() ) | |
1217 | { | |
1218 | // we need to refresh all the lines below the one which was deleted | |
1219 | wxRect rectItem; | |
1220 | if ( item > 0 && GetItemCount() ) | |
1221 | { | |
1222 | GetItemRect(item - 1, rectItem); | |
1223 | } | |
1224 | else | |
1225 | { | |
1226 | rectItem.y = | |
1227 | rectItem.height = 0; | |
1228 | } | |
1229 | ||
1230 | wxRect rectWin = GetRect(); | |
1231 | rectWin.height = rectWin.GetBottom() - rectItem.GetBottom(); | |
1232 | rectWin.y = rectItem.GetBottom(); | |
1233 | ||
1234 | RefreshRect(rectWin); | |
1235 | } | |
1236 | ||
1237 | return TRUE; | |
2bda0e17 KB |
1238 | } |
1239 | ||
1240 | // Deletes all items | |
0b5efdc7 | 1241 | bool wxListCtrl::DeleteAllItems() |
2bda0e17 | 1242 | { |
68c124a1 | 1243 | FreeAllInternalData(); |
2e9f62da | 1244 | return ListView_DeleteAllItems(GetHwnd()) != 0; |
2bda0e17 KB |
1245 | } |
1246 | ||
1247 | // Deletes all items | |
0b5efdc7 | 1248 | bool wxListCtrl::DeleteAllColumns() |
2bda0e17 | 1249 | { |
edccf428 | 1250 | while ( m_colCount > 0 ) |
2bda0e17 | 1251 | { |
edccf428 VZ |
1252 | if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 ) |
1253 | { | |
f6bcfd97 | 1254 | wxLogLastError(wxT("ListView_DeleteColumn")); |
edccf428 VZ |
1255 | |
1256 | return FALSE; | |
1257 | } | |
1258 | ||
1259 | m_colCount--; | |
2bda0e17 | 1260 | } |
edccf428 | 1261 | |
223d09f6 | 1262 | wxASSERT_MSG( m_colCount == 0, wxT("no columns should be left") ); |
edccf428 VZ |
1263 | |
1264 | return TRUE; | |
2bda0e17 KB |
1265 | } |
1266 | ||
1267 | // Deletes a column | |
debe6624 | 1268 | bool wxListCtrl::DeleteColumn(int col) |
2bda0e17 | 1269 | { |
edccf428 | 1270 | bool success = (ListView_DeleteColumn(GetHwnd(), col) != 0); |
2bda0e17 KB |
1271 | |
1272 | if ( success && (m_colCount > 0) ) | |
1273 | m_colCount --; | |
1274 | return success; | |
1275 | } | |
1276 | ||
1277 | // Clears items, and columns if there are any. | |
0b5efdc7 | 1278 | void wxListCtrl::ClearAll() |
2bda0e17 KB |
1279 | { |
1280 | DeleteAllItems(); | |
1281 | if ( m_colCount > 0 ) | |
1282 | DeleteAllColumns(); | |
1283 | } | |
1284 | ||
bbcdf8bc JS |
1285 | wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass) |
1286 | { | |
1287 | wxASSERT( (textControlClass->IsKindOf(CLASSINFO(wxTextCtrl))) ); | |
1288 | ||
6aaef140 | 1289 | // ListView_EditLabel requires that the list has focus. |
aa50e893 | 1290 | SetFocus(); |
2b5f62a0 | 1291 | |
6aaef140 | 1292 | WXHWND hWnd = (WXHWND) ListView_EditLabel(GetHwnd(), item); |
2b5f62a0 VZ |
1293 | if ( !hWnd ) |
1294 | { | |
1295 | // failed to start editing | |
1296 | return NULL; | |
1297 | } | |
bbcdf8bc | 1298 | |
2b5f62a0 VZ |
1299 | // [re]create the text control wrapping the HWND we got |
1300 | if ( m_textCtrl ) | |
bbcdf8bc | 1301 | { |
7bf1474a | 1302 | m_textCtrl->UnsubclassWin(); |
fb718549 | 1303 | m_textCtrl->SetHWND(0); |
0b5efdc7 | 1304 | delete m_textCtrl; |
bbcdf8bc JS |
1305 | } |
1306 | ||
2b5f62a0 | 1307 | m_textCtrl = (wxTextCtrl *)textControlClass->CreateObject(); |
6aaef140 VZ |
1308 | m_textCtrl->SetHWND(hWnd); |
1309 | m_textCtrl->SubclassWin(hWnd); | |
1310 | m_textCtrl->SetParent(this); | |
bbcdf8bc | 1311 | |
2b5f62a0 VZ |
1312 | // we must disallow TABbing away from the control while the edit contol is |
1313 | // shown because this leaves it in some strange state (just try removing | |
1314 | // this line and then pressing TAB while editing an item in listctrl | |
1315 | // inside a panel) | |
1316 | m_textCtrl->SetWindowStyle(m_textCtrl->GetWindowStyle() | wxTE_PROCESS_TAB); | |
1317 | ||
bbcdf8bc JS |
1318 | return m_textCtrl; |
1319 | } | |
1320 | ||
1321 | // End label editing, optionally cancelling the edit | |
33ac7e6f | 1322 | bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel)) |
2bda0e17 | 1323 | { |
7bf1474a VZ |
1324 | wxFAIL_MSG( _T("not implemented") ); |
1325 | ||
0b5efdc7 | 1326 | return FALSE; |
2bda0e17 KB |
1327 | } |
1328 | ||
1329 | // Ensures this item is visible | |
debe6624 | 1330 | bool wxListCtrl::EnsureVisible(long item) |
2bda0e17 | 1331 | { |
7bf1474a | 1332 | return ListView_EnsureVisible(GetHwnd(), (int) item, FALSE) != 0; |
2bda0e17 KB |
1333 | } |
1334 | ||
1335 | // Find an item whose label matches this string, starting from the item after 'start' | |
1336 | // or the beginning if 'start' is -1. | |
debe6624 | 1337 | long wxListCtrl::FindItem(long start, const wxString& str, bool partial) |
2bda0e17 | 1338 | { |
0b5efdc7 | 1339 | LV_FINDINFO findInfo; |
2bda0e17 | 1340 | |
0b5efdc7 VZ |
1341 | findInfo.flags = LVFI_STRING; |
1342 | if ( partial ) | |
7edc258e | 1343 | findInfo.flags |= LVFI_PARTIAL; |
3ca6a5f0 | 1344 | findInfo.psz = str; |
2bda0e17 | 1345 | |
3ca6a5f0 BP |
1346 | // ListView_FindItem() excludes the first item from search and to look |
1347 | // through all the items you need to start from -1 which is unnatural and | |
8036af01 JS |
1348 | // inconsistent with the generic version - so we adjust the index |
1349 | if (start != -1) | |
1350 | start --; | |
1351 | return ListView_FindItem(GetHwnd(), (int) start, &findInfo); | |
2bda0e17 KB |
1352 | } |
1353 | ||
1354 | // Find an item whose data matches this data, starting from the item after 'start' | |
1355 | // or the beginning if 'start' is -1. | |
72db8894 RD |
1356 | // NOTE : Lindsay Mathieson - 14-July-2002 |
1357 | // No longer use ListView_FindItem as the data attribute is now stored | |
1358 | // in a wxListItemInternalData structure refernced by the actual lParam | |
debe6624 | 1359 | long wxListCtrl::FindItem(long start, long data) |
2bda0e17 | 1360 | { |
72db8894 RD |
1361 | long idx = start + 1; |
1362 | long count = GetItemCount(); | |
2bda0e17 | 1363 | |
72db8894 RD |
1364 | while (idx < count) |
1365 | { | |
1366 | if (GetItemData(idx) == data) | |
1367 | return idx; | |
1368 | idx++; | |
1369 | }; | |
2bda0e17 | 1370 | |
72db8894 | 1371 | return -1; |
2bda0e17 KB |
1372 | } |
1373 | ||
1374 | // Find an item nearest this position in the specified direction, starting from | |
1375 | // the item after 'start' or the beginning if 'start' is -1. | |
debe6624 | 1376 | long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction) |
2bda0e17 | 1377 | { |
0b5efdc7 | 1378 | LV_FINDINFO findInfo; |
2bda0e17 | 1379 | |
0b5efdc7 VZ |
1380 | findInfo.flags = LVFI_NEARESTXY; |
1381 | findInfo.pt.x = pt.x; | |
1382 | findInfo.pt.y = pt.y; | |
acb62b84 | 1383 | findInfo.vkDirection = VK_RIGHT; |
2bda0e17 | 1384 | |
0b5efdc7 VZ |
1385 | if ( direction == wxLIST_FIND_UP ) |
1386 | findInfo.vkDirection = VK_UP; | |
1387 | else if ( direction == wxLIST_FIND_DOWN ) | |
1388 | findInfo.vkDirection = VK_DOWN; | |
1389 | else if ( direction == wxLIST_FIND_LEFT ) | |
1390 | findInfo.vkDirection = VK_LEFT; | |
1391 | else if ( direction == wxLIST_FIND_RIGHT ) | |
1392 | findInfo.vkDirection = VK_RIGHT; | |
1393 | ||
edccf428 | 1394 | return ListView_FindItem(GetHwnd(), (int) start, & findInfo); |
2bda0e17 KB |
1395 | } |
1396 | ||
1397 | // Determines which item (if any) is at the specified point, | |
1398 | // giving details in 'flags' (see wxLIST_HITTEST_... flags above) | |
1399 | long wxListCtrl::HitTest(const wxPoint& point, int& flags) | |
1400 | { | |
1401 | LV_HITTESTINFO hitTestInfo; | |
0b5efdc7 VZ |
1402 | hitTestInfo.pt.x = (int) point.x; |
1403 | hitTestInfo.pt.y = (int) point.y; | |
2bda0e17 | 1404 | |
edccf428 | 1405 | ListView_HitTest(GetHwnd(), & hitTestInfo); |
2bda0e17 | 1406 | |
0b5efdc7 VZ |
1407 | flags = 0; |
1408 | if ( hitTestInfo.flags & LVHT_ABOVE ) | |
1409 | flags |= wxLIST_HITTEST_ABOVE; | |
1410 | if ( hitTestInfo.flags & LVHT_BELOW ) | |
1411 | flags |= wxLIST_HITTEST_BELOW; | |
1412 | if ( hitTestInfo.flags & LVHT_NOWHERE ) | |
1413 | flags |= wxLIST_HITTEST_NOWHERE; | |
1414 | if ( hitTestInfo.flags & LVHT_ONITEMICON ) | |
1415 | flags |= wxLIST_HITTEST_ONITEMICON; | |
1416 | if ( hitTestInfo.flags & LVHT_ONITEMLABEL ) | |
1417 | flags |= wxLIST_HITTEST_ONITEMLABEL; | |
1418 | if ( hitTestInfo.flags & LVHT_ONITEMSTATEICON ) | |
1419 | flags |= wxLIST_HITTEST_ONITEMSTATEICON; | |
1420 | if ( hitTestInfo.flags & LVHT_TOLEFT ) | |
1421 | flags |= wxLIST_HITTEST_TOLEFT; | |
1422 | if ( hitTestInfo.flags & LVHT_TORIGHT ) | |
1423 | flags |= wxLIST_HITTEST_TORIGHT; | |
1424 | ||
edccf428 | 1425 | return (long) hitTestInfo.iItem; |
2bda0e17 KB |
1426 | } |
1427 | ||
1428 | // Inserts an item, returning the index of the new item if successful, | |
1429 | // -1 otherwise. | |
2bda0e17 KB |
1430 | long wxListCtrl::InsertItem(wxListItem& info) |
1431 | { | |
98ec9dbe VZ |
1432 | wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") ); |
1433 | ||
0b5efdc7 VZ |
1434 | LV_ITEM item; |
1435 | wxConvertToMSWListItem(this, info, item); | |
7cf46fdb | 1436 | item.mask &= ~LVIF_PARAM; |
2bda0e17 | 1437 | |
7cf46fdb VZ |
1438 | // check wether we need to allocate our internal data |
1439 | bool needInternalData = ((info.m_mask & wxLIST_MASK_DATA) || info.HasAttributes()); | |
1440 | if (needInternalData) | |
bdc72a22 | 1441 | { |
7cf46fdb VZ |
1442 | m_AnyInternalData = TRUE; |
1443 | item.mask |= LVIF_PARAM; | |
2702ed5a | 1444 | |
7cf46fdb VZ |
1445 | // internal stucture that manages data |
1446 | wxListItemInternalData *data = new wxListItemInternalData(); | |
1447 | item.lParam = (LPARAM) data; | |
2702ed5a | 1448 | |
7cf46fdb VZ |
1449 | if (info.m_mask & wxLIST_MASK_DATA) |
1450 | data->lParam = info.m_data; | |
2702ed5a | 1451 | |
7cf46fdb VZ |
1452 | // check whether it has any custom attributes |
1453 | if ( info.HasAttributes() ) | |
1454 | { | |
1455 | // take copy of attributes | |
1456 | data->attr = new wxListItemAttr(*info.GetAttributes()); | |
bdc72a22 | 1457 | } |
7cf46fdb VZ |
1458 | }; |
1459 | ||
68c124a1 RD |
1460 | long rv = ListView_InsertItem(GetHwnd(), & item); |
1461 | m_count += 1; | |
1462 | wxASSERT_MSG( m_count == ListView_GetItemCount(GetHwnd()), | |
1463 | wxT("m_count should match ListView_GetItemCount")); | |
bdc72a22 | 1464 | |
68c124a1 | 1465 | return rv; |
2bda0e17 KB |
1466 | } |
1467 | ||
debe6624 | 1468 | long wxListCtrl::InsertItem(long index, const wxString& label) |
2bda0e17 | 1469 | { |
0b5efdc7 VZ |
1470 | wxListItem info; |
1471 | info.m_text = label; | |
1472 | info.m_mask = wxLIST_MASK_TEXT; | |
1473 | info.m_itemId = index; | |
1474 | return InsertItem(info); | |
2bda0e17 KB |
1475 | } |
1476 | ||
1477 | // Inserts an image item | |
debe6624 | 1478 | long wxListCtrl::InsertItem(long index, int imageIndex) |
2bda0e17 | 1479 | { |
0b5efdc7 VZ |
1480 | wxListItem info; |
1481 | info.m_image = imageIndex; | |
1482 | info.m_mask = wxLIST_MASK_IMAGE; | |
1483 | info.m_itemId = index; | |
1484 | return InsertItem(info); | |
2bda0e17 KB |
1485 | } |
1486 | ||
1487 | // Inserts an image/string item | |
debe6624 | 1488 | long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex) |
2bda0e17 | 1489 | { |
0b5efdc7 VZ |
1490 | wxListItem info; |
1491 | info.m_image = imageIndex; | |
1492 | info.m_text = label; | |
1493 | info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT; | |
1494 | info.m_itemId = index; | |
1495 | return InsertItem(info); | |
2bda0e17 KB |
1496 | } |
1497 | ||
1498 | // For list view mode (only), inserts a column. | |
debe6624 | 1499 | long wxListCtrl::InsertColumn(long col, wxListItem& item) |
2bda0e17 | 1500 | { |
0b5efdc7 | 1501 | LV_COLUMN lvCol; |
6f806543 | 1502 | wxConvertToMSWListCol(col, item, lvCol); |
0b5efdc7 | 1503 | |
6f806543 | 1504 | if ( !(lvCol.mask & LVCF_WIDTH) ) |
e373f51b VZ |
1505 | { |
1506 | // always give some width to the new column: this one is compatible | |
6f806543 VZ |
1507 | // with the generic version |
1508 | lvCol.mask |= LVCF_WIDTH; | |
e373f51b | 1509 | lvCol.cx = 80; |
0b5efdc7 | 1510 | } |
e373f51b | 1511 | |
6f806543 VZ |
1512 | // when we insert a column which can contain an image, we must specify this |
1513 | // flag right now as doing it later in SetColumn() has no effect | |
1514 | // | |
1515 | // we use LVCFMT_BITMAP_ON_RIGHT by default because without it there is no | |
1516 | // way to dynamically set/clear the bitmap as the column without a bitmap | |
1517 | // on the left looks ugly (there is a hole) | |
1518 | // | |
1519 | // unfortunately with my version of comctl32.dll (5.80), the left column | |
1520 | // image is always on the left and it seems that it's a "feature" - I | |
1521 | // didn't find any way to work around it in any case | |
1522 | if ( lvCol.mask & LVCF_IMAGE ) | |
1523 | { | |
1524 | lvCol.mask |= LVCF_FMT; | |
1525 | lvCol.fmt |= LVCFMT_BITMAP_ON_RIGHT; | |
1526 | } | |
2bda0e17 | 1527 | |
6f806543 | 1528 | bool success = ListView_InsertColumn(GetHwnd(), col, &lvCol) != -1; |
2bda0e17 | 1529 | if ( success ) |
e373f51b VZ |
1530 | { |
1531 | m_colCount++; | |
1532 | } | |
1533 | else | |
1534 | { | |
223d09f6 | 1535 | wxLogDebug(wxT("Failed to insert the column '%s' into listview!"), |
e373f51b VZ |
1536 | lvCol.pszText); |
1537 | } | |
1538 | ||
2bda0e17 KB |
1539 | return success; |
1540 | } | |
1541 | ||
bdc72a22 VZ |
1542 | long wxListCtrl::InsertColumn(long col, |
1543 | const wxString& heading, | |
1544 | int format, | |
1545 | int width) | |
2bda0e17 | 1546 | { |
0b5efdc7 VZ |
1547 | wxListItem item; |
1548 | item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT; | |
1549 | item.m_text = heading; | |
1550 | if ( width > -1 ) | |
1551 | { | |
1552 | item.m_mask |= wxLIST_MASK_WIDTH; | |
1553 | item.m_width = width; | |
1554 | } | |
1555 | item.m_format = format; | |
2bda0e17 | 1556 | |
0b5efdc7 | 1557 | return InsertColumn(col, item); |
2bda0e17 KB |
1558 | } |
1559 | ||
2b5f62a0 VZ |
1560 | // scroll the control by the given number of pixels (exception: in list view, |
1561 | // dx is interpreted as number of columns) | |
debe6624 | 1562 | bool wxListCtrl::ScrollList(int dx, int dy) |
2bda0e17 | 1563 | { |
2b5f62a0 VZ |
1564 | if ( !ListView_Scroll(GetHwnd(), dx, dy) ) |
1565 | { | |
1566 | wxLogDebug(_T("ListView_Scroll(%d, %d) failed"), dx, dy); | |
1567 | ||
1568 | return FALSE; | |
1569 | } | |
1570 | ||
1571 | return TRUE; | |
2bda0e17 KB |
1572 | } |
1573 | ||
1574 | // Sort items. | |
1575 | ||
1576 | // fn is a function which takes 3 long arguments: item1, item2, data. | |
1577 | // item1 is the long data associated with a first item (NOT the index). | |
1578 | // item2 is the long data associated with a second item (NOT the index). | |
1579 | // data is the same value as passed to SortItems. | |
1580 | // The return value is a negative number if the first item should precede the second | |
1581 | // item, a positive number of the second item should precede the first, | |
1582 | // or zero if the two items are equivalent. | |
1583 | ||
1584 | // data is arbitrary data to be passed to the sort function. | |
19230604 | 1585 | |
7cf46fdb VZ |
1586 | // Internal structures for proxying the user compare function |
1587 | // so that we can pass it the *real* user data | |
19230604 | 1588 | |
7cf46fdb VZ |
1589 | // translate lParam data and call user func |
1590 | struct wxInternalDataSort | |
19230604 | 1591 | { |
7cf46fdb VZ |
1592 | wxListCtrlCompare user_fn; |
1593 | long data; | |
1594 | }; | |
19230604 | 1595 | |
7cf46fdb | 1596 | int CALLBACK wxInternalDataCompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) |
2bda0e17 | 1597 | { |
7cf46fdb | 1598 | struct wxInternalDataSort *internalData = (struct wxInternalDataSort *) lParamSort; |
19230604 | 1599 | |
7cf46fdb VZ |
1600 | wxListItemInternalData *data1 = (wxListItemInternalData *) lParam1; |
1601 | wxListItemInternalData *data2 = (wxListItemInternalData *) lParam2; | |
19230604 | 1602 | |
7cf46fdb VZ |
1603 | long d1 = (data1 == NULL ? 0 : data1->lParam); |
1604 | long d2 = (data2 == NULL ? 0 : data2->lParam); | |
19230604 | 1605 | |
7cf46fdb | 1606 | return internalData->user_fn(d1, d2, internalData->data); |
19230604 | 1607 | |
7cf46fdb | 1608 | }; |
19230604 | 1609 | |
7cf46fdb VZ |
1610 | bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data) |
1611 | { | |
1612 | struct wxInternalDataSort internalData; | |
1613 | internalData.user_fn = fn; | |
1614 | internalData.data = data; | |
19230604 | 1615 | |
14090241 VZ |
1616 | // WPARAM cast is needed for mingw/cygwin |
1617 | if ( !ListView_SortItems(GetHwnd(), | |
1618 | wxInternalDataCompareFunc, | |
1619 | (WPARAM) &internalData) ) | |
19230604 RD |
1620 | { |
1621 | wxLogDebug(_T("ListView_SortItems() failed")); | |
1622 | ||
1623 | return FALSE; | |
1624 | } | |
1625 | ||
1626 | return TRUE; | |
2bda0e17 KB |
1627 | } |
1628 | ||
19230604 RD |
1629 | |
1630 | ||
edccf428 VZ |
1631 | // ---------------------------------------------------------------------------- |
1632 | // message processing | |
1633 | // ---------------------------------------------------------------------------- | |
1634 | ||
debe6624 | 1635 | bool wxListCtrl::MSWCommand(WXUINT cmd, WXWORD id) |
2bda0e17 | 1636 | { |
0b5efdc7 | 1637 | if (cmd == EN_UPDATE) |
acb62b84 | 1638 | { |
0b5efdc7 VZ |
1639 | wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, id); |
1640 | event.SetEventObject( this ); | |
1641 | ProcessCommand(event); | |
1642 | return TRUE; | |
acb62b84 | 1643 | } |
0b5efdc7 | 1644 | else if (cmd == EN_KILLFOCUS) |
acb62b84 | 1645 | { |
0b5efdc7 VZ |
1646 | wxCommandEvent event(wxEVT_KILL_FOCUS, id); |
1647 | event.SetEventObject( this ); | |
1648 | ProcessCommand(event); | |
1649 | return TRUE; | |
acb62b84 | 1650 | } |
edccf428 VZ |
1651 | else |
1652 | return FALSE; | |
0b5efdc7 VZ |
1653 | } |
1654 | ||
a23fd0e1 | 1655 | bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) |
0b5efdc7 | 1656 | { |
68c124a1 | 1657 | |
bdc72a22 VZ |
1658 | // prepare the event |
1659 | // ----------------- | |
1660 | ||
0b5efdc7 | 1661 | wxListEvent event(wxEVT_NULL, m_windowId); |
648bec3e VZ |
1662 | event.SetEventObject(this); |
1663 | ||
0b5efdc7 | 1664 | wxEventType eventType = wxEVT_NULL; |
225fe9d6 | 1665 | |
bdc72a22 | 1666 | NMHDR *nmhdr = (NMHDR *)lParam; |
225fe9d6 | 1667 | |
d1f2eb1d VZ |
1668 | // if your compiler is as broken as this, you should really change it: this |
1669 | // code is needed for normal operation! #ifdef below is only useful for | |
1670 | // automatic rebuilds which are done with a very old compiler version | |
0cf5b099 | 1671 | #ifdef HDN_BEGINTRACKA |
d1f2eb1d | 1672 | |
11358d39 VZ |
1673 | // check for messages from the header (in report view) |
1674 | HWND hwndHdr = ListView_GetHeader(GetHwnd()); | |
225fe9d6 | 1675 | |
11358d39 VZ |
1676 | // is it a message from the header? |
1677 | if ( nmhdr->hwndFrom == hwndHdr ) | |
acb62b84 | 1678 | { |
00811ff9 | 1679 | HD_NOTIFY *nmHDR = (HD_NOTIFY *)nmhdr; |
0cf5b099 | 1680 | |
11358d39 | 1681 | event.m_itemIndex = -1; |
cb0f56f9 | 1682 | |
11358d39 VZ |
1683 | switch ( nmhdr->code ) |
1684 | { | |
1685 | // yet another comctl32.dll bug: under NT/W2K it sends Unicode | |
1686 | // TRACK messages even to ANSI programs: on my system I get | |
1687 | // HDN_BEGINTRACKW and HDN_ENDTRACKA and no HDN_TRACK at all! | |
1688 | // | |
1689 | // work around is to simply catch both versions and hope that it | |
1690 | // works (why should this message exist in ANSI and Unicode is | |
1691 | // beyond me as it doesn't deal with strings at all...) | |
2b5f62a0 VZ |
1692 | // |
1693 | // note that fr HDN_TRACK another possibility could be to use | |
1694 | // HDN_ITEMCHANGING but it is sent even after HDN_ENDTRACK and when | |
1695 | // something other than the item width changes so we'd have to | |
1696 | // filter out the unwanted events then | |
11358d39 VZ |
1697 | case HDN_BEGINTRACKA: |
1698 | case HDN_BEGINTRACKW: | |
1699 | eventType = wxEVT_COMMAND_LIST_COL_BEGIN_DRAG; | |
1700 | // fall through | |
1701 | ||
1702 | case HDN_TRACKA: | |
1703 | case HDN_TRACKW: | |
1704 | if ( eventType == wxEVT_NULL ) | |
1705 | eventType = wxEVT_COMMAND_LIST_COL_DRAGGING; | |
1706 | // fall through | |
1707 | ||
1708 | case HDN_ENDTRACKA: | |
1709 | case HDN_ENDTRACKW: | |
1710 | if ( eventType == wxEVT_NULL ) | |
1711 | eventType = wxEVT_COMMAND_LIST_COL_END_DRAG; | |
2b5f62a0 VZ |
1712 | |
1713 | event.m_item.m_width = nmHDR->pitem->cxy; | |
11358d39 VZ |
1714 | event.m_col = nmHDR->iItem; |
1715 | break; | |
1716 | ||
1717 | case NM_RCLICK: | |
1718 | { | |
1719 | eventType = wxEVT_COMMAND_LIST_COL_RIGHT_CLICK; | |
1720 | event.m_col = -1; | |
0b5efdc7 | 1721 | |
11358d39 VZ |
1722 | // find the column clicked: we have to search for it |
1723 | // ourselves as the notification message doesn't provide | |
1724 | // this info | |
0b5efdc7 | 1725 | |
11358d39 VZ |
1726 | // where did the click occur? |
1727 | POINT ptClick; | |
1728 | if ( !::GetCursorPos(&ptClick) ) | |
1729 | { | |
1730 | wxLogLastError(_T("GetCursorPos")); | |
1731 | } | |
0b5efdc7 | 1732 | |
11358d39 VZ |
1733 | if ( !::ScreenToClient(hwndHdr, &ptClick) ) |
1734 | { | |
1735 | wxLogLastError(_T("ScreenToClient(listctrl header)")); | |
1736 | } | |
5ea47806 | 1737 | |
11358d39 VZ |
1738 | event.m_pointDrag.x = ptClick.x; |
1739 | event.m_pointDrag.y = ptClick.y; | |
5ea47806 | 1740 | |
11358d39 | 1741 | int colCount = Header_GetItemCount(hwndHdr); |
bdc72a22 | 1742 | |
11358d39 VZ |
1743 | RECT rect; |
1744 | for ( int col = 0; col < colCount; col++ ) | |
1745 | { | |
1746 | if ( Header_GetItemRect(hwndHdr, col, &rect) ) | |
1747 | { | |
1748 | if ( ::PtInRect(&rect, ptClick) ) | |
1749 | { | |
1750 | event.m_col = col; | |
1751 | break; | |
1752 | } | |
1753 | } | |
1754 | } | |
1755 | } | |
1756 | break; | |
5ea47806 | 1757 | |
2b5f62a0 VZ |
1758 | case HDN_GETDISPINFOW: |
1759 | { | |
1760 | LPNMHDDISPINFOW info = (LPNMHDDISPINFOW) lParam; | |
1761 | // This is a fix for a strange bug under XP. | |
1762 | // Normally, info->iItem is a valid index, but | |
1763 | // sometimes this is a silly (large) number | |
1764 | // and when we return FALSE via wxControl::MSWOnNotify | |
1765 | // to indicate that it hasn't yet been processed, | |
1766 | // there's a GPF in Windows. | |
1767 | // By returning TRUE here, we avoid further processing | |
1768 | // of this strange message. | |
7eb833e6 | 1769 | if ( info->iItem >= GetColumnCount() ) |
2b5f62a0 VZ |
1770 | return TRUE; |
1771 | } | |
1772 | // fall through | |
1773 | ||
11358d39 VZ |
1774 | default: |
1775 | return wxControl::MSWOnNotify(idCtrl, lParam, result); | |
1776 | } | |
1777 | } | |
d1f2eb1d | 1778 | else |
0cf5b099 | 1779 | #endif // defined(HDN_BEGINTRACKA) |
d1f2eb1d | 1780 | if ( nmhdr->hwndFrom == GetHwnd() ) |
11358d39 VZ |
1781 | { |
1782 | // almost all messages use NM_LISTVIEW | |
1783 | NM_LISTVIEW *nmLV = (NM_LISTVIEW *)nmhdr; | |
bdc72a22 | 1784 | |
2b5f62a0 VZ |
1785 | const int iItem = nmLV->iItem; |
1786 | ||
68c124a1 RD |
1787 | |
1788 | // FreeAllInternalData will cause LVN_ITEMCHANG* messages, which can be | |
1789 | // ignored for efficiency. It is done here because the internal data is in the | |
1790 | // process of being deleted so we don't want to try and access it below. | |
1791 | if ( m_ignoreChangeMessages && | |
1792 | ( (nmLV->hdr.code == LVN_ITEMCHANGED) || (nmLV->hdr.code == LVN_ITEMCHANGING))) | |
2b5f62a0 | 1793 | { |
68c124a1 RD |
1794 | return TRUE; |
1795 | } | |
7eb833e6 | 1796 | |
2b5f62a0 | 1797 | |
68c124a1 RD |
1798 | // If we have a valid item then check if there is a data value |
1799 | // associated with it and put it in the event. | |
1800 | if ( iItem >= 0 && iItem < GetItemCount() ) | |
1801 | { | |
1802 | wxListItemInternalData *internaldata = | |
1803 | wxGetInternalData(GetHwnd(), iItem); | |
2b5f62a0 | 1804 | |
68c124a1 RD |
1805 | if ( internaldata ) |
1806 | event.m_item.m_data = internaldata->lParam; | |
2b5f62a0 | 1807 | } |
bdc72a22 | 1808 | |
68c124a1 | 1809 | |
11358d39 VZ |
1810 | switch ( nmhdr->code ) |
1811 | { | |
1812 | case LVN_BEGINRDRAG: | |
1813 | eventType = wxEVT_COMMAND_LIST_BEGIN_RDRAG; | |
1814 | // fall through | |
7bf1474a | 1815 | |
11358d39 VZ |
1816 | case LVN_BEGINDRAG: |
1817 | if ( eventType == wxEVT_NULL ) | |
1818 | { | |
1819 | eventType = wxEVT_COMMAND_LIST_BEGIN_DRAG; | |
1820 | } | |
bdc72a22 | 1821 | |
2b5f62a0 | 1822 | event.m_itemIndex = iItem; |
11358d39 VZ |
1823 | event.m_pointDrag.x = nmLV->ptAction.x; |
1824 | event.m_pointDrag.y = nmLV->ptAction.y; | |
1825 | break; | |
1826 | ||
8c21905b VS |
1827 | // NB: we have to handle both *A and *W versions here because some |
1828 | // versions of comctl32.dll send ANSI message to an Unicode app | |
1829 | case LVN_BEGINLABELEDITA: | |
11358d39 VZ |
1830 | { |
1831 | eventType = wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT; | |
8c21905b VS |
1832 | wxLV_ITEM item(((LV_DISPINFOA *)lParam)->item); |
1833 | wxConvertFromMSWListItem(GetHwnd(), event.m_item, item); | |
1834 | event.m_itemIndex = event.m_item.m_itemId; | |
1835 | } | |
1836 | break; | |
1837 | case LVN_BEGINLABELEDITW: | |
1838 | { | |
1839 | eventType = wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT; | |
1840 | wxLV_ITEM item(((LV_DISPINFOW *)lParam)->item); | |
1841 | wxConvertFromMSWListItem(GetHwnd(), event.m_item, item); | |
1842 | event.m_itemIndex = event.m_item.m_itemId; | |
1843 | } | |
1844 | break; | |
1845 | ||
1846 | case LVN_ENDLABELEDITA: | |
1847 | { | |
1848 | eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT; | |
1849 | wxLV_ITEM item(((LV_DISPINFOA *)lParam)->item); | |
1850 | wxConvertFromMSWListItem(NULL, event.m_item, item); | |
73d8c5fd | 1851 | if ( ((LV_ITEM)item).pszText == NULL || |
8c21905b VS |
1852 | ((LV_ITEM)item).iItem == -1 ) |
1853 | return FALSE; | |
1854 | ||
1855 | event.m_itemIndex = event.m_item.m_itemId; | |
1856 | } | |
1857 | break; | |
1858 | case LVN_ENDLABELEDITW: | |
1859 | { | |
1860 | eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT; | |
1861 | wxLV_ITEM item(((LV_DISPINFOW *)lParam)->item); | |
1862 | wxConvertFromMSWListItem(NULL, event.m_item, item); | |
73d8c5fd | 1863 | if ( ((LV_ITEM)item).pszText == NULL || |
8c21905b VS |
1864 | ((LV_ITEM)item).iItem == -1 ) |
1865 | return FALSE; | |
1866 | ||
11358d39 VZ |
1867 | event.m_itemIndex = event.m_item.m_itemId; |
1868 | } | |
1869 | break; | |
edccf428 | 1870 | |
11358d39 VZ |
1871 | case LVN_COLUMNCLICK: |
1872 | eventType = wxEVT_COMMAND_LIST_COL_CLICK; | |
1873 | event.m_itemIndex = -1; | |
1874 | event.m_col = nmLV->iSubItem; | |
1875 | break; | |
bdc72a22 | 1876 | |
11358d39 | 1877 | case LVN_DELETEALLITEMS: |
68c124a1 | 1878 | m_count = 0; |
11358d39 VZ |
1879 | eventType = wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS; |
1880 | event.m_itemIndex = -1; | |
11358d39 VZ |
1881 | break; |
1882 | ||
1883 | case LVN_DELETEITEM: | |
68c124a1 RD |
1884 | if (m_count == 0) |
1885 | // this should be prevented by the post-processing code below, | |
1886 | // but "just in case" | |
1887 | return FALSE; | |
1888 | ||
11358d39 | 1889 | eventType = wxEVT_COMMAND_LIST_DELETE_ITEM; |
2b5f62a0 | 1890 | event.m_itemIndex = iItem; |
7cf46fdb | 1891 | // delete the assoicated internal data |
2b5f62a0 | 1892 | wxDeleteInternalData(this, iItem); |
11358d39 VZ |
1893 | break; |
1894 | ||
11358d39 VZ |
1895 | case LVN_SETDISPINFO: |
1896 | { | |
1897 | eventType = wxEVT_COMMAND_LIST_SET_INFO; | |
1898 | LV_DISPINFO *info = (LV_DISPINFO *)lParam; | |
1899 | wxConvertFromMSWListItem(GetHwnd(), event.m_item, info->item); | |
1900 | } | |
1901 | break; | |
1902 | ||
1903 | case LVN_INSERTITEM: | |
1904 | eventType = wxEVT_COMMAND_LIST_INSERT_ITEM; | |
2b5f62a0 | 1905 | event.m_itemIndex = iItem; |
11358d39 | 1906 | break; |
edccf428 | 1907 | |
11358d39 | 1908 | case LVN_ITEMCHANGED: |
648bec3e VZ |
1909 | // we translate this catch all message into more interesting |
1910 | // (and more easy to process) wxWindows events | |
1911 | ||
2b5f62a0 VZ |
1912 | // first of all, we deal with the state change events only and |
1913 | // only for valid items (item == -1 for the virtual list | |
1914 | // control) | |
1915 | if ( nmLV->uChanged & LVIF_STATE && iItem != -1 ) | |
11358d39 | 1916 | { |
648bec3e VZ |
1917 | // temp vars for readability |
1918 | const UINT stOld = nmLV->uOldState; | |
1919 | const UINT stNew = nmLV->uNewState; | |
1920 | ||
2b5f62a0 VZ |
1921 | event.m_item.SetId(iItem); |
1922 | event.m_item.SetMask(wxLIST_MASK_TEXT | | |
1923 | wxLIST_MASK_IMAGE | | |
1924 | wxLIST_MASK_DATA); | |
1925 | GetItem(event.m_item); | |
1926 | ||
648bec3e VZ |
1927 | // has the focus changed? |
1928 | if ( !(stOld & LVIS_FOCUSED) && (stNew & LVIS_FOCUSED) ) | |
1929 | { | |
1930 | eventType = wxEVT_COMMAND_LIST_ITEM_FOCUSED; | |
2b5f62a0 | 1931 | event.m_itemIndex = iItem; |
648bec3e VZ |
1932 | } |
1933 | ||
1934 | if ( (stNew & LVIS_SELECTED) != (stOld & LVIS_SELECTED) ) | |
1935 | { | |
1936 | if ( eventType != wxEVT_NULL ) | |
1937 | { | |
1938 | // focus and selection have both changed: send the | |
1939 | // focus event from here and the selection one | |
1940 | // below | |
1941 | event.SetEventType(eventType); | |
1942 | (void)GetEventHandler()->ProcessEvent(event); | |
1943 | } | |
1944 | else // no focus event to send | |
1945 | { | |
1946 | // then need to set m_itemIndex as it wasn't done | |
1947 | // above | |
2b5f62a0 | 1948 | event.m_itemIndex = iItem; |
648bec3e VZ |
1949 | } |
1950 | ||
1951 | eventType = stNew & LVIS_SELECTED | |
1952 | ? wxEVT_COMMAND_LIST_ITEM_SELECTED | |
1953 | : wxEVT_COMMAND_LIST_ITEM_DESELECTED; | |
1954 | } | |
edccf428 | 1955 | } |
648bec3e VZ |
1956 | |
1957 | if ( eventType == wxEVT_NULL ) | |
edccf428 | 1958 | { |
648bec3e | 1959 | // not an interesting event for us |
11358d39 | 1960 | return FALSE; |
edccf428 | 1961 | } |
648bec3e | 1962 | |
11358d39 | 1963 | break; |
225fe9d6 | 1964 | |
11358d39 VZ |
1965 | case LVN_KEYDOWN: |
1966 | { | |
1967 | LV_KEYDOWN *info = (LV_KEYDOWN *)lParam; | |
1968 | WORD wVKey = info->wVKey; | |
1969 | ||
1970 | // get the current selection | |
1971 | long lItem = GetNextItem(-1, | |
1972 | wxLIST_NEXT_ALL, | |
1973 | wxLIST_STATE_SELECTED); | |
1974 | ||
1975 | // <Enter> or <Space> activate the selected item if any (but | |
1976 | // not with Shift and/or Ctrl as then they have a predefined | |
1977 | // meaning for the list view) | |
1978 | if ( lItem != -1 && | |
1979 | (wVKey == VK_RETURN || wVKey == VK_SPACE) && | |
1980 | !(wxIsShiftDown() || wxIsCtrlDown()) ) | |
1981 | { | |
1982 | eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED; | |
1983 | } | |
1984 | else | |
1985 | { | |
1986 | eventType = wxEVT_COMMAND_LIST_KEY_DOWN; | |
185d0094 VZ |
1987 | |
1988 | // wxCharCodeMSWToWX() returns 0 if the key is an ASCII | |
1989 | // value which should be used as is | |
1990 | int code = wxCharCodeMSWToWX(wVKey); | |
1991 | event.m_code = code ? code : wVKey; | |
11358d39 | 1992 | } |
7db91489 | 1993 | |
11358d39 VZ |
1994 | event.m_itemIndex = |
1995 | event.m_item.m_itemId = lItem; | |
1996 | ||
1997 | if ( lItem != -1 ) | |
1998 | { | |
1999 | // fill the other fields too | |
2000 | event.m_item.m_text = GetItemText(lItem); | |
2001 | event.m_item.m_data = GetItemData(lItem); | |
2002 | } | |
2003 | } | |
2004 | break; | |
2005 | ||
2006 | case NM_DBLCLK: | |
2007 | // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do | |
2008 | // anything else | |
2009 | if ( wxControl::MSWOnNotify(idCtrl, lParam, result) ) | |
f6bcfd97 | 2010 | { |
11358d39 | 2011 | return TRUE; |
f6bcfd97 | 2012 | } |
edccf428 | 2013 | |
11358d39 VZ |
2014 | // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event |
2015 | // if it happened on an item (and not on empty place) | |
2b5f62a0 | 2016 | if ( iItem == -1 ) |
11358d39 VZ |
2017 | { |
2018 | // not on item | |
2019 | return FALSE; | |
2020 | } | |
edccf428 | 2021 | |
11358d39 | 2022 | eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED; |
2b5f62a0 VZ |
2023 | event.m_itemIndex = iItem; |
2024 | event.m_item.m_text = GetItemText(iItem); | |
2025 | event.m_item.m_data = GetItemData(iItem); | |
11358d39 | 2026 | break; |
225fe9d6 | 2027 | |
11358d39 | 2028 | case NM_RCLICK: |
225fe9d6 VZ |
2029 | // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(), |
2030 | // don't do anything else | |
2031 | if ( wxControl::MSWOnNotify(idCtrl, lParam, result) ) | |
2032 | { | |
2033 | return TRUE; | |
2034 | } | |
cb0f56f9 | 2035 | |
225fe9d6 VZ |
2036 | // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event |
2037 | LV_HITTESTINFO lvhti; | |
2038 | wxZeroMemory(lvhti); | |
11c7d5b6 | 2039 | |
225fe9d6 VZ |
2040 | ::GetCursorPos(&(lvhti.pt)); |
2041 | ::ScreenToClient(GetHwnd(),&(lvhti.pt)); | |
2042 | if ( ListView_HitTest(GetHwnd(),&lvhti) != -1 ) | |
cb0f56f9 | 2043 | { |
225fe9d6 VZ |
2044 | if ( lvhti.flags & LVHT_ONITEM ) |
2045 | { | |
2046 | eventType = wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK; | |
2047 | event.m_itemIndex = lvhti.iItem; | |
a1f79c1e VZ |
2048 | event.m_pointDrag.x = lvhti.pt.x; |
2049 | event.m_pointDrag.y = lvhti.pt.y; | |
225fe9d6 | 2050 | } |
cb0f56f9 | 2051 | } |
11358d39 | 2052 | break; |
bdc72a22 | 2053 | |
bf9b6266 | 2054 | #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \ |
11358d39 VZ |
2055 | && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) ) |
2056 | case NM_CUSTOMDRAW: | |
2057 | *result = OnCustomDraw(lParam); | |
63166611 | 2058 | |
11358d39 | 2059 | return TRUE; |
6ecfe2ac | 2060 | #endif // _WIN32_IE >= 0x300 |
0b5efdc7 | 2061 | |
11358d39 VZ |
2062 | case LVN_ODCACHEHINT: |
2063 | { | |
2064 | const NM_CACHEHINT *cacheHint = (NM_CACHEHINT *)lParam; | |
614391dc | 2065 | |
11358d39 | 2066 | eventType = wxEVT_COMMAND_LIST_CACHE_HINT; |
e623926d | 2067 | |
11358d39 VZ |
2068 | // we get some really stupid cache hints like ones for items in |
2069 | // range 0..0 for an empty control or, after deleting an item, | |
2070 | // for items in invalid range - filter this garbage out | |
2071 | if ( cacheHint->iFrom < cacheHint->iTo ) | |
2072 | { | |
2073 | event.m_oldItemIndex = cacheHint->iFrom; | |
e623926d | 2074 | |
11358d39 VZ |
2075 | long iMax = GetItemCount(); |
2076 | event.m_itemIndex = cacheHint->iTo < iMax ? cacheHint->iTo | |
2077 | : iMax - 1; | |
2078 | } | |
2079 | else | |
2080 | { | |
2081 | return FALSE; | |
2082 | } | |
e623926d | 2083 | } |
11358d39 | 2084 | break; |
614391dc | 2085 | |
11358d39 VZ |
2086 | case LVN_GETDISPINFO: |
2087 | if ( IsVirtual() ) | |
2088 | { | |
2089 | LV_DISPINFO *info = (LV_DISPINFO *)lParam; | |
98ec9dbe | 2090 | |
11358d39 VZ |
2091 | LV_ITEM& lvi = info->item; |
2092 | long item = lvi.iItem; | |
98ec9dbe | 2093 | |
11358d39 VZ |
2094 | if ( lvi.mask & LVIF_TEXT ) |
2095 | { | |
2096 | wxString text = OnGetItemText(item, lvi.iSubItem); | |
2097 | wxStrncpy(lvi.pszText, text, lvi.cchTextMax); | |
2098 | } | |
98ec9dbe | 2099 | |
244531bc | 2100 | #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \ |
5145e34f | 2101 | && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) ) |
11358d39 VZ |
2102 | if ( lvi.mask & LVIF_IMAGE ) |
2103 | { | |
2104 | lvi.iImage = OnGetItemImage(item); | |
2105 | } | |
244531bc | 2106 | #endif |
98ec9dbe | 2107 | |
11358d39 VZ |
2108 | // a little dose of healthy paranoia: as we never use |
2109 | // LVM_SETCALLBACKMASK we're not supposed to get these ones | |
2110 | wxASSERT_MSG( !(lvi.mask & LVIF_STATE), | |
2111 | _T("we don't support state callbacks yet!") ); | |
98ec9dbe | 2112 | |
11358d39 VZ |
2113 | return TRUE; |
2114 | } | |
2115 | // fall through | |
98ec9dbe | 2116 | |
11358d39 VZ |
2117 | default: |
2118 | return wxControl::MSWOnNotify(idCtrl, lParam, result); | |
2119 | } | |
2120 | } | |
2121 | else | |
2122 | { | |
2123 | // where did this one come from? | |
2124 | return FALSE; | |
acb62b84 VZ |
2125 | } |
2126 | ||
bdc72a22 VZ |
2127 | // process the event |
2128 | // ----------------- | |
2129 | ||
0b5efdc7 | 2130 | event.SetEventType(eventType); |
acb62b84 | 2131 | |
68c124a1 | 2132 | bool processed = GetEventHandler()->ProcessEvent(event); |
acb62b84 | 2133 | |
bdc72a22 VZ |
2134 | // post processing |
2135 | // --------------- | |
225fe9d6 | 2136 | switch ( nmhdr->code ) |
acb62b84 | 2137 | { |
6932a32c VZ |
2138 | case LVN_DELETEALLITEMS: |
2139 | // always return TRUE to suppress all additional LVN_DELETEITEM | |
2140 | // notifications - this makes deleting all items from a list ctrl | |
2141 | // much faster | |
2142 | *result = TRUE; | |
6932a32c VZ |
2143 | return TRUE; |
2144 | ||
8c21905b VS |
2145 | case LVN_ENDLABELEDITA: |
2146 | case LVN_ENDLABELEDITW: | |
614391dc VZ |
2147 | // logic here is inversed compared to all the other messages |
2148 | *result = event.IsAllowed(); | |
2149 | ||
2b5f62a0 VZ |
2150 | // don't keep a stale wxTextCtrl around |
2151 | if ( m_textCtrl ) | |
2152 | { | |
2153 | // EDIT control will be deleted by the list control itself so | |
2154 | // prevent us from deleting it as well | |
2b5f62a0 | 2155 | m_textCtrl->UnsubclassWin(); |
fb718549 | 2156 | m_textCtrl->SetHWND(0); |
2b5f62a0 VZ |
2157 | delete m_textCtrl; |
2158 | m_textCtrl = NULL; | |
2159 | } | |
2160 | ||
614391dc | 2161 | return TRUE; |
acb62b84 | 2162 | } |
acb62b84 | 2163 | |
68c124a1 RD |
2164 | if ( processed ) |
2165 | *result = !event.IsAllowed(); | |
fd3f686c | 2166 | |
68c124a1 | 2167 | return processed; |
2bda0e17 KB |
2168 | } |
2169 | ||
63166611 VZ |
2170 | #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 |
2171 | ||
2172 | WXLPARAM wxListCtrl::OnCustomDraw(WXLPARAM lParam) | |
2173 | { | |
2174 | LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam; | |
2175 | NMCUSTOMDRAW& nmcd = lplvcd->nmcd; | |
2176 | switch ( nmcd.dwDrawStage ) | |
2177 | { | |
2178 | case CDDS_PREPAINT: | |
2179 | // if we've got any items with non standard attributes, | |
2180 | // notify us before painting each item | |
2181 | // | |
2182 | // for virtual controls, always suppose that we have attributes as | |
2183 | // there is no way to check for this | |
2184 | return IsVirtual() || m_hasAnyAttr ? CDRF_NOTIFYITEMDRAW | |
2185 | : CDRF_DODEFAULT; | |
2186 | ||
2187 | case CDDS_ITEMPREPAINT: | |
2188 | { | |
2189 | size_t item = (size_t)nmcd.dwItemSpec; | |
a7f560a2 VZ |
2190 | if ( item >= (size_t)GetItemCount() ) |
2191 | { | |
2192 | // we get this message with item == 0 for an empty control, | |
2193 | // we must ignore it as calling OnGetItemAttr() would be | |
2194 | // wrong | |
2195 | return CDRF_DODEFAULT; | |
2196 | } | |
2197 | ||
63166611 VZ |
2198 | wxListItemAttr *attr = |
2199 | IsVirtual() ? OnGetItemAttr(item) | |
6149de71 | 2200 | : wxGetInternalDataAttr(this, item); |
63166611 VZ |
2201 | |
2202 | if ( !attr ) | |
2203 | { | |
2204 | // nothing to do for this item | |
2205 | return CDRF_DODEFAULT; | |
2206 | } | |
2207 | ||
2208 | HFONT hFont; | |
2209 | wxColour colText, colBack; | |
2210 | if ( attr->HasFont() ) | |
2211 | { | |
2212 | wxFont font = attr->GetFont(); | |
2213 | hFont = (HFONT)font.GetResourceHandle(); | |
2214 | } | |
2215 | else | |
2216 | { | |
2217 | hFont = 0; | |
2218 | } | |
2219 | ||
2220 | if ( attr->HasTextColour() ) | |
2221 | { | |
2222 | colText = attr->GetTextColour(); | |
2223 | } | |
2224 | else | |
2225 | { | |
2226 | colText = GetTextColour(); | |
2227 | } | |
2228 | ||
2229 | if ( attr->HasBackgroundColour() ) | |
2230 | { | |
2231 | colBack = attr->GetBackgroundColour(); | |
2232 | } | |
2233 | else | |
2234 | { | |
2235 | colBack = GetBackgroundColour(); | |
2236 | } | |
2237 | ||
2238 | lplvcd->clrText = wxColourToRGB(colText); | |
2239 | lplvcd->clrTextBk = wxColourToRGB(colBack); | |
2240 | ||
2241 | // note that if we wanted to set colours for | |
2242 | // individual columns (subitems), we would have | |
2243 | // returned CDRF_NOTIFYSUBITEMREDRAW from here | |
2244 | if ( hFont ) | |
2245 | { | |
2246 | ::SelectObject(nmcd.hdc, hFont); | |
2247 | ||
2248 | return CDRF_NEWFONT; | |
2249 | } | |
2250 | } | |
2251 | // fall through to return CDRF_DODEFAULT | |
2252 | ||
2253 | default: | |
2254 | return CDRF_DODEFAULT; | |
2255 | } | |
2256 | } | |
2257 | ||
2258 | #endif // NM_CUSTOMDRAW supported | |
2259 | ||
2702ed5a JS |
2260 | // Necessary for drawing hrules and vrules, if specified |
2261 | void wxListCtrl::OnPaint(wxPaintEvent& event) | |
2262 | { | |
2263 | wxPaintDC dc(this); | |
2264 | ||
2265 | wxControl::OnPaint(event); | |
2266 | ||
2267 | // Reset the device origin since it may have been set | |
2268 | dc.SetDeviceOrigin(0, 0); | |
2269 | ||
2270 | bool drawHRules = ((GetWindowStyle() & wxLC_HRULES) != 0); | |
2271 | bool drawVRules = ((GetWindowStyle() & wxLC_VRULES) != 0); | |
2272 | ||
2273 | if (!drawHRules && !drawVRules) | |
2274 | return; | |
2275 | if ((GetWindowStyle() & wxLC_REPORT) == 0) | |
2276 | return; | |
2277 | ||
a756f210 | 2278 | wxPen pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID); |
2702ed5a JS |
2279 | dc.SetPen(pen); |
2280 | dc.SetBrush(* wxTRANSPARENT_BRUSH); | |
2281 | ||
2282 | wxSize clientSize = GetClientSize(); | |
2283 | wxRect itemRect; | |
2284 | int cy=0; | |
2285 | ||
2702ed5a JS |
2286 | int itemCount = GetItemCount(); |
2287 | int i; | |
625cb8c0 | 2288 | if (drawHRules) |
2702ed5a | 2289 | { |
6443de02 RD |
2290 | long top = GetTopItem(); |
2291 | for (i = top; i < top + GetCountPerPage() + 1; i++) | |
2702ed5a | 2292 | { |
625cb8c0 | 2293 | if (GetItemRect(i, itemRect)) |
ca286917 | 2294 | { |
625cb8c0 RD |
2295 | cy = itemRect.GetTop(); |
2296 | if (i != 0) // Don't draw the first one | |
2297 | { | |
2298 | dc.DrawLine(0, cy, clientSize.x, cy); | |
2299 | } | |
2300 | // Draw last line | |
2cefcb34 | 2301 | if (i == itemCount - 1) |
625cb8c0 RD |
2302 | { |
2303 | cy = itemRect.GetBottom(); | |
2304 | dc.DrawLine(0, cy, clientSize.x, cy); | |
2305 | } | |
2702ed5a JS |
2306 | } |
2307 | } | |
2308 | } | |
2cefcb34 | 2309 | i = itemCount - 1; |
2702ed5a JS |
2310 | if (drawVRules && (i > -1)) |
2311 | { | |
2312 | wxRect firstItemRect; | |
2313 | GetItemRect(0, firstItemRect); | |
2314 | ||
2315 | if (GetItemRect(i, itemRect)) | |
2316 | { | |
2317 | int col; | |
2318 | int x = itemRect.GetX(); | |
2319 | for (col = 0; col < GetColumnCount(); col++) | |
2320 | { | |
2321 | int colWidth = GetColumnWidth(col); | |
2322 | x += colWidth ; | |
e7d073c3 | 2323 | dc.DrawLine(x-1, firstItemRect.GetY() - 2, x-1, itemRect.GetBottom()); |
2702ed5a JS |
2324 | } |
2325 | } | |
2326 | } | |
2327 | } | |
2328 | ||
98ec9dbe VZ |
2329 | // ---------------------------------------------------------------------------- |
2330 | // virtual list controls | |
2331 | // ---------------------------------------------------------------------------- | |
2332 | ||
d699f48b | 2333 | wxString wxListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const |
98ec9dbe VZ |
2334 | { |
2335 | // this is a pure virtual function, in fact - which is not really pure | |
2336 | // because the controls which are not virtual don't need to implement it | |
271d1110 | 2337 | wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") ); |
98ec9dbe VZ |
2338 | |
2339 | return wxEmptyString; | |
2340 | } | |
2341 | ||
d699f48b | 2342 | int wxListCtrl::OnGetItemImage(long WXUNUSED(item)) const |
98ec9dbe VZ |
2343 | { |
2344 | // same as above | |
271d1110 | 2345 | wxFAIL_MSG( _T("wxListCtrl::OnGetItemImage not supposed to be called") ); |
98ec9dbe VZ |
2346 | |
2347 | return -1; | |
2348 | } | |
2349 | ||
d699f48b | 2350 | wxListItemAttr *wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)) const |
6c02c329 | 2351 | { |
63166611 | 2352 | wxASSERT_MSG( item >= 0 && item < GetItemCount(), |
6c02c329 VZ |
2353 | _T("invalid item index in OnGetItemAttr()") ); |
2354 | ||
2355 | // no attributes by default | |
2356 | return NULL; | |
2357 | } | |
2358 | ||
98ec9dbe VZ |
2359 | void wxListCtrl::SetItemCount(long count) |
2360 | { | |
2361 | wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") ); | |
2362 | ||
2363 | if ( !::SendMessage(GetHwnd(), LVM_SETITEMCOUNT, (WPARAM)count, 0) ) | |
2364 | { | |
2365 | wxLogLastError(_T("ListView_SetItemCount")); | |
2366 | } | |
68c124a1 RD |
2367 | m_count = count; |
2368 | wxASSERT_MSG( m_count == ListView_GetItemCount(GetHwnd()), | |
2369 | wxT("m_count should match ListView_GetItemCount")); | |
98ec9dbe VZ |
2370 | } |
2371 | ||
a7f560a2 VZ |
2372 | void wxListCtrl::RefreshItem(long item) |
2373 | { | |
2d33aec9 VZ |
2374 | // strangely enough, ListView_Update() results in much more flicker here |
2375 | // than a dumb Refresh() -- why? | |
2376 | #if 0 | |
a7f560a2 VZ |
2377 | if ( !ListView_Update(GetHwnd(), item) ) |
2378 | { | |
2379 | wxLogLastError(_T("ListView_Update")); | |
2380 | } | |
2d33aec9 VZ |
2381 | #else // 1 |
2382 | wxRect rect; | |
2383 | GetItemRect(item, rect); | |
2384 | RefreshRect(rect); | |
2385 | #endif // 0/1 | |
a7f560a2 VZ |
2386 | } |
2387 | ||
2388 | void wxListCtrl::RefreshItems(long itemFrom, long itemTo) | |
2389 | { | |
d0debf52 VZ |
2390 | wxRect rect1, rect2; |
2391 | GetItemRect(itemFrom, rect1); | |
2392 | GetItemRect(itemTo, rect2); | |
2393 | ||
2394 | wxRect rect = rect1; | |
2395 | rect.height = rect2.GetBottom() - rect1.GetTop(); | |
2396 | ||
2397 | RefreshRect(rect); | |
a7f560a2 VZ |
2398 | } |
2399 | ||
6149de71 | 2400 | static wxListItemInternalData *wxGetInternalData(HWND hwnd, long itemId) |
7cf46fdb VZ |
2401 | { |
2402 | LV_ITEM it; | |
2403 | it.mask = LVIF_PARAM; | |
2404 | it.iItem = itemId; | |
2405 | ||
2406 | bool success = ListView_GetItem(hwnd, &it) != 0; | |
2407 | if (success) | |
2408 | return (wxListItemInternalData *) it.lParam; | |
2409 | else | |
2410 | return NULL; | |
2411 | }; | |
2412 | ||
6149de71 | 2413 | static wxListItemInternalData *wxGetInternalData(wxListCtrl *ctl, long itemId) |
7cf46fdb | 2414 | { |
6149de71 | 2415 | return wxGetInternalData((HWND) ctl->GetHWND(), itemId); |
7cf46fdb VZ |
2416 | }; |
2417 | ||
6149de71 | 2418 | static wxListItemAttr *wxGetInternalDataAttr(wxListCtrl *ctl, long itemId) |
7cf46fdb | 2419 | { |
6149de71 | 2420 | wxListItemInternalData *data = wxGetInternalData(ctl, itemId); |
7cf46fdb VZ |
2421 | if (data) |
2422 | return data->attr; | |
2423 | else | |
2424 | return NULL; | |
2425 | }; | |
2426 | ||
6149de71 RD |
2427 | static void wxDeleteInternalData(wxListCtrl* ctl, long itemId) |
2428 | { | |
2429 | wxListItemInternalData *data = wxGetInternalData(ctl, itemId); | |
2430 | if (data) | |
2431 | { | |
2432 | delete data; | |
2433 | LV_ITEM item; | |
2434 | memset(&item, 0, sizeof(item)); | |
2435 | item.iItem = itemId; | |
2436 | item.mask = LVIF_PARAM; | |
2437 | item.lParam = (LPARAM) 0; | |
2438 | ListView_SetItem((HWND)ctl->GetHWND(), &item); | |
2439 | } | |
2440 | } | |
7cf46fdb | 2441 | |
8dff2b5c VZ |
2442 | static void wxConvertFromMSWListItem(HWND hwndListCtrl, |
2443 | wxListItem& info, | |
2444 | LV_ITEM& lvItem) | |
2bda0e17 | 2445 | { |
73d8c5fd | 2446 | wxListItemInternalData *internaldata = |
7cf46fdb VZ |
2447 | (wxListItemInternalData *) lvItem.lParam; |
2448 | ||
2449 | if (internaldata) | |
2450 | info.m_data = internaldata->lParam; | |
2451 | ||
0b5efdc7 VZ |
2452 | info.m_mask = 0; |
2453 | info.m_state = 0; | |
2454 | info.m_stateMask = 0; | |
2455 | info.m_itemId = lvItem.iItem; | |
acb62b84 | 2456 | |
0b5efdc7 | 2457 | long oldMask = lvItem.mask; |
acb62b84 | 2458 | |
0b5efdc7 | 2459 | bool needText = FALSE; |
8dff2b5c | 2460 | if (hwndListCtrl != 0) |
acb62b84 | 2461 | { |
0b5efdc7 VZ |
2462 | if ( lvItem.mask & LVIF_TEXT ) |
2463 | needText = FALSE; | |
2464 | else | |
2465 | needText = TRUE; | |
acb62b84 | 2466 | |
0b5efdc7 VZ |
2467 | if ( needText ) |
2468 | { | |
837e5743 | 2469 | lvItem.pszText = new wxChar[513]; |
0b5efdc7 VZ |
2470 | lvItem.cchTextMax = 512; |
2471 | } | |
edccf428 | 2472 | lvItem.mask |= LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM; |
8dff2b5c | 2473 | ::SendMessage(hwndListCtrl, LVM_GETITEM, 0, (LPARAM)& lvItem); |
0b5efdc7 | 2474 | } |
acb62b84 | 2475 | |
0b5efdc7 | 2476 | if ( lvItem.mask & LVIF_STATE ) |
acb62b84 | 2477 | { |
0b5efdc7 VZ |
2478 | info.m_mask |= wxLIST_MASK_STATE; |
2479 | ||
2480 | if ( lvItem.stateMask & LVIS_CUT) | |
2481 | { | |
edccf428 | 2482 | info.m_stateMask |= wxLIST_STATE_CUT; |
0b5efdc7 | 2483 | if ( lvItem.state & LVIS_CUT ) |
edccf428 | 2484 | info.m_state |= wxLIST_STATE_CUT; |
0b5efdc7 VZ |
2485 | } |
2486 | if ( lvItem.stateMask & LVIS_DROPHILITED) | |
2487 | { | |
edccf428 | 2488 | info.m_stateMask |= wxLIST_STATE_DROPHILITED; |
0b5efdc7 | 2489 | if ( lvItem.state & LVIS_DROPHILITED ) |
edccf428 | 2490 | info.m_state |= wxLIST_STATE_DROPHILITED; |
0b5efdc7 VZ |
2491 | } |
2492 | if ( lvItem.stateMask & LVIS_FOCUSED) | |
2493 | { | |
edccf428 | 2494 | info.m_stateMask |= wxLIST_STATE_FOCUSED; |
0b5efdc7 | 2495 | if ( lvItem.state & LVIS_FOCUSED ) |
edccf428 | 2496 | info.m_state |= wxLIST_STATE_FOCUSED; |
0b5efdc7 VZ |
2497 | } |
2498 | if ( lvItem.stateMask & LVIS_SELECTED) | |
2499 | { | |
edccf428 | 2500 | info.m_stateMask |= wxLIST_STATE_SELECTED; |
0b5efdc7 | 2501 | if ( lvItem.state & LVIS_SELECTED ) |
edccf428 | 2502 | info.m_state |= wxLIST_STATE_SELECTED; |
0b5efdc7 | 2503 | } |
acb62b84 | 2504 | } |
0b5efdc7 VZ |
2505 | |
2506 | if ( lvItem.mask & LVIF_TEXT ) | |
acb62b84 | 2507 | { |
0b5efdc7 VZ |
2508 | info.m_mask |= wxLIST_MASK_TEXT; |
2509 | info.m_text = lvItem.pszText; | |
acb62b84 | 2510 | } |
0b5efdc7 | 2511 | if ( lvItem.mask & LVIF_IMAGE ) |
acb62b84 | 2512 | { |
0b5efdc7 VZ |
2513 | info.m_mask |= wxLIST_MASK_IMAGE; |
2514 | info.m_image = lvItem.iImage; | |
acb62b84 | 2515 | } |
0b5efdc7 VZ |
2516 | if ( lvItem.mask & LVIF_PARAM ) |
2517 | info.m_mask |= wxLIST_MASK_DATA; | |
2518 | if ( lvItem.mask & LVIF_DI_SETITEM ) | |
2519 | info.m_mask |= wxLIST_SET_ITEM; | |
2520 | info.m_col = lvItem.iSubItem; | |
2521 | ||
2522 | if (needText) | |
acb62b84 | 2523 | { |
0b5efdc7 VZ |
2524 | if (lvItem.pszText) |
2525 | delete[] lvItem.pszText; | |
acb62b84 | 2526 | } |
edccf428 | 2527 | lvItem.mask = oldMask; |
2bda0e17 KB |
2528 | } |
2529 | ||
8dff2b5c VZ |
2530 | static void wxConvertToMSWFlags(long state, long stateMask, LV_ITEM& lvItem) |
2531 | { | |
2532 | if (stateMask & wxLIST_STATE_CUT) | |
2533 | { | |
2534 | lvItem.stateMask |= LVIS_CUT; | |
2535 | if (state & wxLIST_STATE_CUT) | |
2536 | lvItem.state |= LVIS_CUT; | |
2537 | } | |
2538 | if (stateMask & wxLIST_STATE_DROPHILITED) | |
2539 | { | |
2540 | lvItem.stateMask |= LVIS_DROPHILITED; | |
2541 | if (state & wxLIST_STATE_DROPHILITED) | |
2542 | lvItem.state |= LVIS_DROPHILITED; | |
2543 | } | |
2544 | if (stateMask & wxLIST_STATE_FOCUSED) | |
2545 | { | |
2546 | lvItem.stateMask |= LVIS_FOCUSED; | |
2547 | if (state & wxLIST_STATE_FOCUSED) | |
2548 | lvItem.state |= LVIS_FOCUSED; | |
2549 | } | |
2550 | if (stateMask & wxLIST_STATE_SELECTED) | |
2551 | { | |
2552 | lvItem.stateMask |= LVIS_SELECTED; | |
2553 | if (state & wxLIST_STATE_SELECTED) | |
2554 | lvItem.state |= LVIS_SELECTED; | |
2555 | } | |
2556 | } | |
2557 | ||
2558 | static void wxConvertToMSWListItem(const wxListCtrl *ctrl, | |
2559 | const wxListItem& info, | |
2560 | LV_ITEM& lvItem) | |
2bda0e17 | 2561 | { |
edccf428 | 2562 | lvItem.iItem = (int) info.m_itemId; |
acb62b84 | 2563 | |
edccf428 | 2564 | lvItem.iImage = info.m_image; |
0b5efdc7 VZ |
2565 | lvItem.stateMask = 0; |
2566 | lvItem.state = 0; | |
2567 | lvItem.mask = 0; | |
2568 | lvItem.iSubItem = info.m_col; | |
acb62b84 | 2569 | |
0b5efdc7 | 2570 | if (info.m_mask & wxLIST_MASK_STATE) |
acb62b84 | 2571 | { |
edccf428 | 2572 | lvItem.mask |= LVIF_STATE; |
8dff2b5c VZ |
2573 | |
2574 | wxConvertToMSWFlags(info.m_state, info.m_stateMask, lvItem); | |
acb62b84 | 2575 | } |
acb62b84 | 2576 | |
0b5efdc7 | 2577 | if (info.m_mask & wxLIST_MASK_TEXT) |
acb62b84 | 2578 | { |
edccf428 | 2579 | lvItem.mask |= LVIF_TEXT; |
0b5efdc7 VZ |
2580 | if ( ctrl->GetWindowStyleFlag() & wxLC_USER_TEXT ) |
2581 | { | |
2582 | lvItem.pszText = LPSTR_TEXTCALLBACK; | |
2583 | } | |
2584 | else | |
2585 | { | |
e421922f VZ |
2586 | // pszText is not const, hence the cast |
2587 | lvItem.pszText = (wxChar *)info.m_text.c_str(); | |
0b5efdc7 VZ |
2588 | if ( lvItem.pszText ) |
2589 | lvItem.cchTextMax = info.m_text.Length(); | |
2590 | else | |
2591 | lvItem.cchTextMax = 0; | |
2592 | } | |
acb62b84 | 2593 | } |
0b5efdc7 | 2594 | if (info.m_mask & wxLIST_MASK_IMAGE) |
edccf428 | 2595 | lvItem.mask |= LVIF_IMAGE; |
2bda0e17 KB |
2596 | } |
2597 | ||
574c939e | 2598 | static void wxConvertToMSWListCol(int WXUNUSED(col), const wxListItem& item, |
6f806543 VZ |
2599 | LV_COLUMN& lvCol) |
2600 | { | |
2601 | wxZeroMemory(lvCol); | |
2602 | ||
2603 | if ( item.m_mask & wxLIST_MASK_TEXT ) | |
2604 | { | |
2605 | lvCol.mask |= LVCF_TEXT; | |
2606 | lvCol.pszText = (wxChar *)item.m_text.c_str(); // cast is safe | |
2607 | } | |
2608 | ||
2609 | if ( item.m_mask & wxLIST_MASK_FORMAT ) | |
2610 | { | |
2611 | lvCol.mask |= LVCF_FMT; | |
2612 | ||
2613 | if ( item.m_format == wxLIST_FORMAT_LEFT ) | |
2614 | lvCol.fmt = LVCFMT_LEFT; | |
2615 | else if ( item.m_format == wxLIST_FORMAT_RIGHT ) | |
2616 | lvCol.fmt = LVCFMT_RIGHT; | |
2617 | else if ( item.m_format == wxLIST_FORMAT_CENTRE ) | |
2618 | lvCol.fmt = LVCFMT_CENTER; | |
2619 | } | |
2620 | ||
2621 | if ( item.m_mask & wxLIST_MASK_WIDTH ) | |
2622 | { | |
2623 | lvCol.mask |= LVCF_WIDTH; | |
2624 | if ( item.m_width == wxLIST_AUTOSIZE) | |
2625 | lvCol.cx = LVSCW_AUTOSIZE; | |
2626 | else if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER) | |
2627 | lvCol.cx = LVSCW_AUTOSIZE_USEHEADER; | |
2628 | else | |
2629 | lvCol.cx = item.m_width; | |
2630 | } | |
2631 | ||
244531bc | 2632 | #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \ |
5145e34f | 2633 | && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) ) |
6f806543 VZ |
2634 | if ( item.m_mask & wxLIST_MASK_IMAGE ) |
2635 | { | |
2636 | if ( wxTheApp->GetComCtl32Version() >= 470 ) | |
2637 | { | |
2638 | lvCol.mask |= LVCF_IMAGE; | |
2639 | lvCol.iImage = item.m_image; | |
2640 | } | |
2641 | //else: it doesn't support item images anyhow | |
2642 | } | |
244531bc | 2643 | #endif |
6f806543 VZ |
2644 | } |
2645 | ||
1e6feb95 | 2646 | #endif // wxUSE_LISTCTRL |