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