]>
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 | ||
6f806543 | 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 | { | |
614 | if (lvCol.fmt == LVCFMT_LEFT) | |
615 | item.m_format = wxLIST_FORMAT_LEFT; | |
616 | else if (lvCol.fmt == LVCFMT_RIGHT) | |
617 | item.m_format = wxLIST_FORMAT_RIGHT; | |
618 | else if (lvCol.fmt == LVCFMT_CENTER) | |
619 | item.m_format = wxLIST_FORMAT_CENTRE; | |
2bda0e17 KB |
620 | } |
621 | ||
37094564 RD |
622 | if ( item.m_mask & wxLIST_MASK_IMAGE ) |
623 | { | |
624 | item.m_image = lvCol.iImage; | |
625 | } | |
626 | ||
0b5efdc7 | 627 | return success; |
2bda0e17 KB |
628 | } |
629 | ||
630 | // Sets information about this column | |
debe6624 | 631 | bool wxListCtrl::SetColumn(int col, wxListItem& item) |
2bda0e17 | 632 | { |
0b5efdc7 | 633 | LV_COLUMN lvCol; |
6f806543 | 634 | wxConvertToMSWListCol(col, item, lvCol); |
0b5efdc7 | 635 | |
6f806543 | 636 | return ListView_SetColumn(GetHwnd(), col, &lvCol) != 0; |
2bda0e17 KB |
637 | } |
638 | ||
639 | // Gets the column width | |
debe6624 | 640 | int wxListCtrl::GetColumnWidth(int col) const |
2bda0e17 | 641 | { |
edccf428 | 642 | return ListView_GetColumnWidth(GetHwnd(), col); |
2bda0e17 KB |
643 | } |
644 | ||
645 | // Sets the column width | |
debe6624 | 646 | bool wxListCtrl::SetColumnWidth(int col, int width) |
2bda0e17 | 647 | { |
0b5efdc7 VZ |
648 | int col2 = col; |
649 | if ( m_windowStyle & wxLC_LIST ) | |
650 | col2 = -1; | |
2bda0e17 | 651 | |
0b5efdc7 VZ |
652 | int width2 = width; |
653 | if ( width2 == wxLIST_AUTOSIZE) | |
654 | width2 = LVSCW_AUTOSIZE; | |
655 | else if ( width2 == wxLIST_AUTOSIZE_USEHEADER) | |
656 | width2 = LVSCW_AUTOSIZE_USEHEADER; | |
2bda0e17 | 657 | |
6f806543 | 658 | return ListView_SetColumnWidth(GetHwnd(), col2, width2) != 0; |
2bda0e17 KB |
659 | } |
660 | ||
661 | // Gets the number of items that can fit vertically in the | |
662 | // visible area of the list control (list or report view) | |
663 | // or the total number of items in the list control (icon | |
664 | // or small icon view) | |
c42404a5 | 665 | int wxListCtrl::GetCountPerPage() const |
2bda0e17 | 666 | { |
edccf428 | 667 | return ListView_GetCountPerPage(GetHwnd()); |
2bda0e17 KB |
668 | } |
669 | ||
670 | // Gets the edit control for editing labels. | |
c42404a5 | 671 | wxTextCtrl* wxListCtrl::GetEditControl() const |
2bda0e17 | 672 | { |
bbcdf8bc | 673 | return m_textCtrl; |
2bda0e17 KB |
674 | } |
675 | ||
676 | // Gets information about the item | |
677 | bool wxListCtrl::GetItem(wxListItem& info) const | |
678 | { | |
0b5efdc7 | 679 | LV_ITEM lvItem; |
11c7d5b6 | 680 | wxZeroMemory(lvItem); |
2bda0e17 | 681 | |
0b5efdc7 | 682 | lvItem.iItem = info.m_itemId; |
fc5a93cd | 683 | lvItem.iSubItem = info.m_col; |
0b5efdc7 VZ |
684 | |
685 | if ( info.m_mask & wxLIST_MASK_TEXT ) | |
686 | { | |
687 | lvItem.mask |= LVIF_TEXT; | |
837e5743 | 688 | lvItem.pszText = new wxChar[513]; |
0b5efdc7 VZ |
689 | lvItem.cchTextMax = 512; |
690 | } | |
691 | else | |
692 | { | |
693 | lvItem.pszText = NULL; | |
694 | } | |
695 | ||
696 | if (info.m_mask & wxLIST_MASK_DATA) | |
edccf428 | 697 | lvItem.mask |= LVIF_PARAM; |
0b5efdc7 | 698 | |
2189c644 JS |
699 | if (info.m_mask & wxLIST_MASK_IMAGE) |
700 | lvItem.mask |= LVIF_IMAGE; | |
701 | ||
0b5efdc7 VZ |
702 | if ( info.m_mask & wxLIST_MASK_STATE ) |
703 | { | |
704 | lvItem.mask |= LVIF_STATE; | |
705 | // the other bits are hardly interesting anyhow | |
706 | lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED; | |
707 | } | |
708 | ||
709 | bool success = ListView_GetItem((HWND)GetHWND(), &lvItem) != 0; | |
710 | if ( !success ) | |
711 | { | |
712 | wxLogError(_("Couldn't retrieve information about list control item %d."), | |
713 | lvItem.iItem); | |
714 | } | |
715 | else | |
716 | { | |
dccde0c0 VZ |
717 | // give NULL as hwnd as we already have everything we need |
718 | wxConvertFromMSWListItem(NULL, info, lvItem); | |
0b5efdc7 VZ |
719 | } |
720 | ||
721 | if (lvItem.pszText) | |
722 | delete[] lvItem.pszText; | |
723 | ||
724 | return success; | |
2bda0e17 KB |
725 | } |
726 | ||
727 | // Sets information about the item | |
728 | bool wxListCtrl::SetItem(wxListItem& info) | |
729 | { | |
0b5efdc7 | 730 | LV_ITEM item; |
2bda0e17 | 731 | wxConvertToMSWListItem(this, info, item); |
bdc72a22 | 732 | |
7cf46fdb VZ |
733 | // we never update the lParam if it contains our pointer |
734 | // to the wxListItemInternalData structure | |
735 | item.mask &= ~LVIF_PARAM; | |
736 | ||
737 | // check if setting attributes or lParam | |
738 | if (info.HasAttributes() || (info.m_mask & wxLIST_MASK_DATA)) | |
739 | { | |
740 | // get internal item data | |
741 | // perhaps a cache here ? | |
6149de71 | 742 | wxListItemInternalData *data = wxGetInternalData(this, info.m_itemId); |
73d8c5fd | 743 | |
7cf46fdb VZ |
744 | if (! data) |
745 | { | |
746 | // need to set it | |
747 | m_AnyInternalData = TRUE; | |
748 | data = new wxListItemInternalData(); | |
749 | item.lParam = (LPARAM) data; | |
750 | item.mask |= LVIF_PARAM; | |
751 | }; | |
752 | ||
753 | ||
754 | // user data | |
755 | if (info.m_mask & wxLIST_MASK_DATA) | |
756 | data->lParam = info.m_data; | |
757 | ||
758 | // attributes | |
759 | if (info.HasAttributes()) | |
760 | { | |
761 | if (data->attr) | |
762 | *data->attr = *info.GetAttributes(); | |
763 | else | |
764 | data->attr = new wxListItemAttr(*info.GetAttributes()); | |
765 | }; | |
766 | }; | |
767 | ||
768 | ||
2d33aec9 VZ |
769 | // we could be changing only the attribute in which case we don't need to |
770 | // call ListView_SetItem() at all | |
771 | if ( item.mask ) | |
bdc72a22 | 772 | { |
2d33aec9 VZ |
773 | item.cchTextMax = 0; |
774 | if ( !ListView_SetItem(GetHwnd(), &item) ) | |
775 | { | |
776 | wxLogDebug(_T("ListView_SetItem() failed")); | |
2702ed5a | 777 | |
2d33aec9 VZ |
778 | return FALSE; |
779 | } | |
233d0295 | 780 | } |
2702ed5a | 781 | |
233d0295 VZ |
782 | // we need to update the item immediately to show the new image |
783 | bool updateNow = (info.m_mask & wxLIST_MASK_IMAGE) != 0; | |
2702ed5a | 784 | |
233d0295 VZ |
785 | // check whether it has any custom attributes |
786 | if ( info.HasAttributes() ) | |
787 | { | |
bdc72a22 | 788 | m_hasAnyAttr = TRUE; |
233d0295 VZ |
789 | |
790 | // if the colour has changed, we must redraw the item | |
791 | updateNow = TRUE; | |
bdc72a22 | 792 | } |
bdc72a22 | 793 | |
233d0295 | 794 | if ( updateNow ) |
7cc98b3e | 795 | { |
233d0295 | 796 | // we need this to make the change visible right now |
2d33aec9 | 797 | RefreshItem(item.iItem); |
7cc98b3e VZ |
798 | } |
799 | ||
233d0295 | 800 | return TRUE; |
2bda0e17 KB |
801 | } |
802 | ||
debe6624 | 803 | long wxListCtrl::SetItem(long index, int col, const wxString& label, int imageId) |
2bda0e17 | 804 | { |
0b5efdc7 VZ |
805 | wxListItem info; |
806 | info.m_text = label; | |
807 | info.m_mask = wxLIST_MASK_TEXT; | |
808 | info.m_itemId = index; | |
809 | info.m_col = col; | |
810 | if ( imageId > -1 ) | |
811 | { | |
812 | info.m_image = imageId; | |
813 | info.m_mask |= wxLIST_MASK_IMAGE; | |
814 | } | |
815 | return SetItem(info); | |
2bda0e17 KB |
816 | } |
817 | ||
818 | ||
819 | // Gets the item state | |
debe6624 | 820 | int wxListCtrl::GetItemState(long item, long stateMask) const |
2bda0e17 | 821 | { |
0b5efdc7 | 822 | wxListItem info; |
2bda0e17 | 823 | |
edccf428 | 824 | info.m_mask = wxLIST_MASK_STATE; |
0b5efdc7 VZ |
825 | info.m_stateMask = stateMask; |
826 | info.m_itemId = item; | |
2bda0e17 | 827 | |
0b5efdc7 VZ |
828 | if (!GetItem(info)) |
829 | return 0; | |
2bda0e17 | 830 | |
0b5efdc7 | 831 | return info.m_state; |
2bda0e17 KB |
832 | } |
833 | ||
834 | // Sets the item state | |
debe6624 | 835 | bool wxListCtrl::SetItemState(long item, long state, long stateMask) |
2bda0e17 | 836 | { |
8dff2b5c VZ |
837 | // NB: don't use SetItem() here as it doesn't work with the virtual list |
838 | // controls | |
839 | LV_ITEM lvItem; | |
840 | wxZeroMemory(lvItem); | |
2bda0e17 | 841 | |
8dff2b5c | 842 | wxConvertToMSWFlags(state, stateMask, lvItem); |
2bda0e17 | 843 | |
2d33aec9 | 844 | // for the virtual list controls we need to refresh the previously focused |
ad9f477d VZ |
845 | // item manually when changing focus without changing selection |
846 | // programmatically because otherwise it keeps its focus rectangle until | |
847 | // next repaint (yet another comctl32 bug) | |
2d33aec9 VZ |
848 | long focusOld; |
849 | if ( IsVirtual() && | |
850 | (stateMask & wxLIST_STATE_FOCUSED) && | |
851 | (state & wxLIST_STATE_FOCUSED) ) | |
852 | { | |
853 | focusOld = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED); | |
854 | } | |
855 | else | |
856 | { | |
857 | focusOld = -1; | |
858 | } | |
859 | ||
8dff2b5c VZ |
860 | if ( !::SendMessage(GetHwnd(), LVM_SETITEMSTATE, |
861 | (WPARAM)item, (LPARAM)&lvItem) ) | |
862 | { | |
863 | wxLogLastError(_T("ListView_SetItemState")); | |
864 | ||
865 | return FALSE; | |
866 | } | |
867 | ||
2d33aec9 VZ |
868 | if ( focusOld != -1 ) |
869 | { | |
ad9f477d VZ |
870 | // no need to refresh the item if it was previously selected, it would |
871 | // only result in annoying flicker | |
872 | if ( !(GetItemState(focusOld, | |
873 | wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED) ) | |
874 | { | |
875 | RefreshItem(focusOld); | |
876 | } | |
2d33aec9 VZ |
877 | } |
878 | ||
8dff2b5c | 879 | return TRUE; |
2bda0e17 KB |
880 | } |
881 | ||
882 | // Sets the item image | |
33ac7e6f | 883 | bool wxListCtrl::SetItemImage(long item, int image, int WXUNUSED(selImage)) |
2bda0e17 | 884 | { |
0b5efdc7 | 885 | wxListItem info; |
2bda0e17 | 886 | |
edccf428 | 887 | info.m_mask = wxLIST_MASK_IMAGE; |
0b5efdc7 VZ |
888 | info.m_image = image; |
889 | info.m_itemId = item; | |
2bda0e17 | 890 | |
0b5efdc7 | 891 | return SetItem(info); |
2bda0e17 KB |
892 | } |
893 | ||
894 | // Gets the item text | |
debe6624 | 895 | wxString wxListCtrl::GetItemText(long item) const |
2bda0e17 | 896 | { |
0b5efdc7 | 897 | wxListItem info; |
2bda0e17 | 898 | |
edccf428 | 899 | info.m_mask = wxLIST_MASK_TEXT; |
0b5efdc7 | 900 | info.m_itemId = item; |
2bda0e17 | 901 | |
0b5efdc7 VZ |
902 | if (!GetItem(info)) |
903 | return wxString(""); | |
904 | return info.m_text; | |
2bda0e17 KB |
905 | } |
906 | ||
907 | // Sets the item text | |
debe6624 | 908 | void wxListCtrl::SetItemText(long item, const wxString& str) |
2bda0e17 | 909 | { |
0b5efdc7 | 910 | wxListItem info; |
2bda0e17 | 911 | |
edccf428 | 912 | info.m_mask = wxLIST_MASK_TEXT; |
0b5efdc7 VZ |
913 | info.m_itemId = item; |
914 | info.m_text = str; | |
2bda0e17 | 915 | |
0b5efdc7 | 916 | SetItem(info); |
2bda0e17 KB |
917 | } |
918 | ||
919 | // Gets the item data | |
debe6624 | 920 | long wxListCtrl::GetItemData(long item) const |
2bda0e17 | 921 | { |
0b5efdc7 | 922 | wxListItem info; |
2bda0e17 | 923 | |
edccf428 | 924 | info.m_mask = wxLIST_MASK_DATA; |
0b5efdc7 | 925 | info.m_itemId = item; |
2bda0e17 | 926 | |
0b5efdc7 VZ |
927 | if (!GetItem(info)) |
928 | return 0; | |
929 | return info.m_data; | |
2bda0e17 KB |
930 | } |
931 | ||
932 | // Sets the item data | |
debe6624 | 933 | bool wxListCtrl::SetItemData(long item, long data) |
2bda0e17 | 934 | { |
0b5efdc7 | 935 | wxListItem info; |
2bda0e17 | 936 | |
edccf428 | 937 | info.m_mask = wxLIST_MASK_DATA; |
0b5efdc7 VZ |
938 | info.m_itemId = item; |
939 | info.m_data = data; | |
2bda0e17 | 940 | |
0b5efdc7 | 941 | return SetItem(info); |
2bda0e17 KB |
942 | } |
943 | ||
944 | // Gets the item rectangle | |
16e93305 | 945 | bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const |
2bda0e17 | 946 | { |
2d33aec9 | 947 | RECT rectWin; |
2bda0e17 | 948 | |
2d33aec9 | 949 | int codeWin; |
0b5efdc7 | 950 | if ( code == wxLIST_RECT_BOUNDS ) |
2d33aec9 | 951 | codeWin = LVIR_BOUNDS; |
0b5efdc7 | 952 | else if ( code == wxLIST_RECT_ICON ) |
2d33aec9 | 953 | codeWin = LVIR_ICON; |
0b5efdc7 | 954 | else if ( code == wxLIST_RECT_LABEL ) |
2d33aec9 VZ |
955 | codeWin = LVIR_LABEL; |
956 | else | |
957 | { | |
958 | wxFAIL_MSG( _T("incorrect code in GetItemRect()") ); | |
959 | ||
960 | codeWin = LVIR_BOUNDS; | |
961 | } | |
2bda0e17 | 962 | |
5ea105e0 | 963 | #ifdef __WXWINE__ |
2d33aec9 | 964 | bool success = ListView_GetItemRect(GetHwnd(), (int) item, &rectWin ) != 0; |
5ea105e0 | 965 | #else |
2d33aec9 | 966 | bool success = ListView_GetItemRect(GetHwnd(), (int) item, &rectWin, codeWin) != 0; |
5ea105e0 | 967 | #endif |
2bda0e17 | 968 | |
2d33aec9 VZ |
969 | rect.x = rectWin.left; |
970 | rect.y = rectWin.top; | |
971 | rect.width = rectWin.right - rectWin.left; | |
972 | rect.height = rectWin.bottom - rectWin.top; | |
973 | ||
0b5efdc7 | 974 | return success; |
2bda0e17 KB |
975 | } |
976 | ||
977 | // Gets the item position | |
debe6624 | 978 | bool wxListCtrl::GetItemPosition(long item, wxPoint& pos) const |
2bda0e17 | 979 | { |
0b5efdc7 | 980 | POINT pt; |
2bda0e17 | 981 | |
edccf428 | 982 | bool success = (ListView_GetItemPosition(GetHwnd(), (int) item, &pt) != 0); |
2bda0e17 | 983 | |
0b5efdc7 VZ |
984 | pos.x = pt.x; pos.y = pt.y; |
985 | return success; | |
2bda0e17 KB |
986 | } |
987 | ||
988 | // Sets the item position. | |
debe6624 | 989 | bool wxListCtrl::SetItemPosition(long item, const wxPoint& pos) |
2bda0e17 | 990 | { |
edccf428 | 991 | return (ListView_SetItemPosition(GetHwnd(), (int) item, pos.x, pos.y) != 0); |
2bda0e17 KB |
992 | } |
993 | ||
994 | // Gets the number of items in the list control | |
c42404a5 | 995 | int wxListCtrl::GetItemCount() const |
2bda0e17 | 996 | { |
edccf428 | 997 | return ListView_GetItemCount(GetHwnd()); |
2bda0e17 KB |
998 | } |
999 | ||
1000 | // Retrieves the spacing between icons in pixels. | |
1001 | // If small is TRUE, gets the spacing for the small icon | |
1002 | // view, otherwise the large icon view. | |
1003 | int wxListCtrl::GetItemSpacing(bool isSmall) const | |
1004 | { | |
edccf428 | 1005 | return ListView_GetItemSpacing(GetHwnd(), (BOOL) isSmall); |
2bda0e17 KB |
1006 | } |
1007 | ||
5b98eb2f RL |
1008 | void wxListCtrl::SetItemTextColour( long item, const wxColour &col ) |
1009 | { | |
1010 | wxListItem info; | |
1011 | info.m_itemId = item; | |
1012 | info.SetTextColour( col ); | |
1013 | SetItem( info ); | |
1014 | } | |
1015 | ||
1016 | wxColour wxListCtrl::GetItemTextColour( long item ) const | |
1017 | { | |
1018 | wxListItem info; | |
1019 | info.m_itemId = item; | |
1020 | GetItem( info ); | |
1021 | return info.GetTextColour(); | |
1022 | } | |
1023 | ||
1024 | void wxListCtrl::SetItemBackgroundColour( long item, const wxColour &col ) | |
1025 | { | |
1026 | wxListItem info; | |
1027 | info.m_itemId = item; | |
1028 | info.SetBackgroundColour( col ); | |
1029 | SetItem( info ); | |
1030 | } | |
1031 | ||
1032 | wxColour wxListCtrl::GetItemBackgroundColour( long item ) const | |
1033 | { | |
1034 | wxListItem info; | |
1035 | info.m_itemId = item; | |
1036 | GetItem( info ); | |
1037 | return info.GetBackgroundColour(); | |
1038 | } | |
1039 | ||
2bda0e17 | 1040 | // Gets the number of selected items in the list control |
c42404a5 | 1041 | int wxListCtrl::GetSelectedItemCount() const |
2bda0e17 | 1042 | { |
edccf428 | 1043 | return ListView_GetSelectedCount(GetHwnd()); |
2bda0e17 KB |
1044 | } |
1045 | ||
1046 | // Gets the text colour of the listview | |
c42404a5 | 1047 | wxColour wxListCtrl::GetTextColour() const |
2bda0e17 | 1048 | { |
edccf428 | 1049 | COLORREF ref = ListView_GetTextColor(GetHwnd()); |
0b5efdc7 VZ |
1050 | wxColour col(GetRValue(ref), GetGValue(ref), GetBValue(ref)); |
1051 | return col; | |
2bda0e17 KB |
1052 | } |
1053 | ||
1054 | // Sets the text colour of the listview | |
1055 | void wxListCtrl::SetTextColour(const wxColour& col) | |
1056 | { | |
910484a6 | 1057 | ListView_SetTextColor(GetHwnd(), PALETTERGB(col.Red(), col.Green(), col.Blue())); |
2bda0e17 KB |
1058 | } |
1059 | ||
1060 | // Gets the index of the topmost visible item when in | |
1061 | // list or report view | |
c42404a5 | 1062 | long wxListCtrl::GetTopItem() const |
2bda0e17 | 1063 | { |
edccf428 | 1064 | return (long) ListView_GetTopIndex(GetHwnd()); |
2bda0e17 KB |
1065 | } |
1066 | ||
1067 | // Searches for an item, starting from 'item'. | |
1068 | // 'geometry' is one of | |
1069 | // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT. | |
1070 | // 'state' is a state bit flag, one or more of | |
1071 | // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT. | |
1072 | // item can be -1 to find the first item that matches the | |
1073 | // specified flags. | |
1074 | // Returns the item or -1 if unsuccessful. | |
debe6624 | 1075 | long wxListCtrl::GetNextItem(long item, int geom, int state) const |
2bda0e17 | 1076 | { |
0b5efdc7 | 1077 | long flags = 0; |
2bda0e17 | 1078 | |
0b5efdc7 VZ |
1079 | if ( geom == wxLIST_NEXT_ABOVE ) |
1080 | flags |= LVNI_ABOVE; | |
1081 | if ( geom == wxLIST_NEXT_ALL ) | |
1082 | flags |= LVNI_ALL; | |
1083 | if ( geom == wxLIST_NEXT_BELOW ) | |
1084 | flags |= LVNI_BELOW; | |
1085 | if ( geom == wxLIST_NEXT_LEFT ) | |
1086 | flags |= LVNI_TOLEFT; | |
1087 | if ( geom == wxLIST_NEXT_RIGHT ) | |
1088 | flags |= LVNI_TORIGHT; | |
2bda0e17 | 1089 | |
0b5efdc7 VZ |
1090 | if ( state & wxLIST_STATE_CUT ) |
1091 | flags |= LVNI_CUT; | |
1092 | if ( state & wxLIST_STATE_DROPHILITED ) | |
1093 | flags |= LVNI_DROPHILITED; | |
1094 | if ( state & wxLIST_STATE_FOCUSED ) | |
1095 | flags |= LVNI_FOCUSED; | |
1096 | if ( state & wxLIST_STATE_SELECTED ) | |
1097 | flags |= LVNI_SELECTED; | |
2bda0e17 | 1098 | |
edccf428 | 1099 | return (long) ListView_GetNextItem(GetHwnd(), item, flags); |
2bda0e17 KB |
1100 | } |
1101 | ||
1102 | ||
debe6624 | 1103 | wxImageList *wxListCtrl::GetImageList(int which) const |
2bda0e17 | 1104 | { |
0b5efdc7 | 1105 | if ( which == wxIMAGE_LIST_NORMAL ) |
2bda0e17 | 1106 | { |
0b5efdc7 VZ |
1107 | return m_imageListNormal; |
1108 | } | |
1109 | else if ( which == wxIMAGE_LIST_SMALL ) | |
2bda0e17 | 1110 | { |
0b5efdc7 VZ |
1111 | return m_imageListSmall; |
1112 | } | |
1113 | else if ( which == wxIMAGE_LIST_STATE ) | |
2bda0e17 | 1114 | { |
0b5efdc7 VZ |
1115 | return m_imageListState; |
1116 | } | |
1117 | return NULL; | |
2bda0e17 KB |
1118 | } |
1119 | ||
debe6624 | 1120 | void wxListCtrl::SetImageList(wxImageList *imageList, int which) |
2bda0e17 | 1121 | { |
0b5efdc7 VZ |
1122 | int flags = 0; |
1123 | if ( which == wxIMAGE_LIST_NORMAL ) | |
2bda0e17 | 1124 | { |
0b5efdc7 | 1125 | flags = LVSIL_NORMAL; |
2e12c11a | 1126 | if (m_ownsImageListNormal) delete m_imageListNormal; |
0b5efdc7 | 1127 | m_imageListNormal = imageList; |
2e12c11a | 1128 | m_ownsImageListNormal = FALSE; |
0b5efdc7 VZ |
1129 | } |
1130 | else if ( which == wxIMAGE_LIST_SMALL ) | |
2bda0e17 | 1131 | { |
0b5efdc7 | 1132 | flags = LVSIL_SMALL; |
2e12c11a | 1133 | if (m_ownsImageListSmall) delete m_imageListSmall; |
0b5efdc7 | 1134 | m_imageListSmall = imageList; |
2e12c11a | 1135 | m_ownsImageListSmall = FALSE; |
0b5efdc7 VZ |
1136 | } |
1137 | else if ( which == wxIMAGE_LIST_STATE ) | |
2bda0e17 | 1138 | { |
0b5efdc7 | 1139 | flags = LVSIL_STATE; |
2e12c11a | 1140 | if (m_ownsImageListState) delete m_imageListState; |
0b5efdc7 | 1141 | m_imageListState = imageList; |
2e12c11a | 1142 | m_ownsImageListState = FALSE; |
0b5efdc7 | 1143 | } |
edccf428 | 1144 | ListView_SetImageList(GetHwnd(), (HIMAGELIST) imageList ? imageList->GetHIMAGELIST() : 0, flags); |
2bda0e17 KB |
1145 | } |
1146 | ||
2e12c11a VS |
1147 | void wxListCtrl::AssignImageList(wxImageList *imageList, int which) |
1148 | { | |
1149 | SetImageList(imageList, which); | |
1150 | if ( which == wxIMAGE_LIST_NORMAL ) | |
1151 | m_ownsImageListNormal = TRUE; | |
1152 | else if ( which == wxIMAGE_LIST_SMALL ) | |
1153 | m_ownsImageListSmall = TRUE; | |
1154 | else if ( which == wxIMAGE_LIST_STATE ) | |
1155 | m_ownsImageListState = TRUE; | |
1156 | } | |
1157 | ||
edccf428 | 1158 | // ---------------------------------------------------------------------------- |
2bda0e17 | 1159 | // Operations |
edccf428 | 1160 | // ---------------------------------------------------------------------------- |
2bda0e17 KB |
1161 | |
1162 | // Arranges the items | |
debe6624 | 1163 | bool wxListCtrl::Arrange(int flag) |
2bda0e17 | 1164 | { |
0b5efdc7 VZ |
1165 | UINT code = 0; |
1166 | if ( flag == wxLIST_ALIGN_LEFT ) | |
1167 | code = LVA_ALIGNLEFT; | |
1168 | else if ( flag == wxLIST_ALIGN_TOP ) | |
1169 | code = LVA_ALIGNTOP; | |
1170 | else if ( flag == wxLIST_ALIGN_DEFAULT ) | |
1171 | code = LVA_DEFAULT; | |
1172 | else if ( flag == wxLIST_ALIGN_SNAP_TO_GRID ) | |
1173 | code = LVA_SNAPTOGRID; | |
2bda0e17 | 1174 | |
edccf428 | 1175 | return (ListView_Arrange(GetHwnd(), code) != 0); |
2bda0e17 KB |
1176 | } |
1177 | ||
1178 | // Deletes an item | |
debe6624 | 1179 | bool wxListCtrl::DeleteItem(long item) |
2bda0e17 | 1180 | { |
2e9f62da VZ |
1181 | if ( !ListView_DeleteItem(GetHwnd(), (int) item) ) |
1182 | { | |
1183 | wxLogLastError(_T("ListView_DeleteItem")); | |
1184 | return FALSE; | |
1185 | } | |
1186 | ||
1187 | // the virtual list control doesn't refresh itself correctly, help it | |
1188 | if ( IsVirtual() ) | |
1189 | { | |
1190 | // we need to refresh all the lines below the one which was deleted | |
1191 | wxRect rectItem; | |
1192 | if ( item > 0 && GetItemCount() ) | |
1193 | { | |
1194 | GetItemRect(item - 1, rectItem); | |
1195 | } | |
1196 | else | |
1197 | { | |
1198 | rectItem.y = | |
1199 | rectItem.height = 0; | |
1200 | } | |
1201 | ||
1202 | wxRect rectWin = GetRect(); | |
1203 | rectWin.height = rectWin.GetBottom() - rectItem.GetBottom(); | |
1204 | rectWin.y = rectItem.GetBottom(); | |
1205 | ||
1206 | RefreshRect(rectWin); | |
1207 | } | |
1208 | ||
1209 | return TRUE; | |
2bda0e17 KB |
1210 | } |
1211 | ||
1212 | // Deletes all items | |
0b5efdc7 | 1213 | bool wxListCtrl::DeleteAllItems() |
2bda0e17 | 1214 | { |
2e9f62da | 1215 | return ListView_DeleteAllItems(GetHwnd()) != 0; |
2bda0e17 KB |
1216 | } |
1217 | ||
1218 | // Deletes all items | |
0b5efdc7 | 1219 | bool wxListCtrl::DeleteAllColumns() |
2bda0e17 | 1220 | { |
edccf428 | 1221 | while ( m_colCount > 0 ) |
2bda0e17 | 1222 | { |
edccf428 VZ |
1223 | if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 ) |
1224 | { | |
f6bcfd97 | 1225 | wxLogLastError(wxT("ListView_DeleteColumn")); |
edccf428 VZ |
1226 | |
1227 | return FALSE; | |
1228 | } | |
1229 | ||
1230 | m_colCount--; | |
2bda0e17 | 1231 | } |
edccf428 | 1232 | |
223d09f6 | 1233 | wxASSERT_MSG( m_colCount == 0, wxT("no columns should be left") ); |
edccf428 VZ |
1234 | |
1235 | return TRUE; | |
2bda0e17 KB |
1236 | } |
1237 | ||
1238 | // Deletes a column | |
debe6624 | 1239 | bool wxListCtrl::DeleteColumn(int col) |
2bda0e17 | 1240 | { |
edccf428 | 1241 | bool success = (ListView_DeleteColumn(GetHwnd(), col) != 0); |
2bda0e17 KB |
1242 | |
1243 | if ( success && (m_colCount > 0) ) | |
1244 | m_colCount --; | |
1245 | return success; | |
1246 | } | |
1247 | ||
1248 | // Clears items, and columns if there are any. | |
0b5efdc7 | 1249 | void wxListCtrl::ClearAll() |
2bda0e17 KB |
1250 | { |
1251 | DeleteAllItems(); | |
1252 | if ( m_colCount > 0 ) | |
1253 | DeleteAllColumns(); | |
1254 | } | |
1255 | ||
bbcdf8bc JS |
1256 | wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass) |
1257 | { | |
1258 | wxASSERT( (textControlClass->IsKindOf(CLASSINFO(wxTextCtrl))) ); | |
1259 | ||
6aaef140 | 1260 | // ListView_EditLabel requires that the list has focus. |
aa50e893 | 1261 | SetFocus(); |
6aaef140 | 1262 | WXHWND hWnd = (WXHWND) ListView_EditLabel(GetHwnd(), item); |
bbcdf8bc JS |
1263 | |
1264 | if (m_textCtrl) | |
1265 | { | |
0b5efdc7 | 1266 | m_textCtrl->SetHWND(0); |
7bf1474a | 1267 | m_textCtrl->UnsubclassWin(); |
0b5efdc7 | 1268 | delete m_textCtrl; |
bbcdf8bc JS |
1269 | } |
1270 | ||
1271 | m_textCtrl = (wxTextCtrl*) textControlClass->CreateObject(); | |
6aaef140 VZ |
1272 | m_textCtrl->SetHWND(hWnd); |
1273 | m_textCtrl->SubclassWin(hWnd); | |
1274 | m_textCtrl->SetParent(this); | |
bbcdf8bc JS |
1275 | |
1276 | return m_textCtrl; | |
1277 | } | |
1278 | ||
1279 | // End label editing, optionally cancelling the edit | |
33ac7e6f | 1280 | bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel)) |
2bda0e17 | 1281 | { |
7bf1474a VZ |
1282 | wxFAIL_MSG( _T("not implemented") ); |
1283 | ||
0b5efdc7 | 1284 | return FALSE; |
2bda0e17 KB |
1285 | } |
1286 | ||
1287 | // Ensures this item is visible | |
debe6624 | 1288 | bool wxListCtrl::EnsureVisible(long item) |
2bda0e17 | 1289 | { |
7bf1474a | 1290 | return ListView_EnsureVisible(GetHwnd(), (int) item, FALSE) != 0; |
2bda0e17 KB |
1291 | } |
1292 | ||
1293 | // Find an item whose label matches this string, starting from the item after 'start' | |
1294 | // or the beginning if 'start' is -1. | |
debe6624 | 1295 | long wxListCtrl::FindItem(long start, const wxString& str, bool partial) |
2bda0e17 | 1296 | { |
0b5efdc7 | 1297 | LV_FINDINFO findInfo; |
2bda0e17 | 1298 | |
0b5efdc7 VZ |
1299 | findInfo.flags = LVFI_STRING; |
1300 | if ( partial ) | |
7edc258e | 1301 | findInfo.flags |= LVFI_PARTIAL; |
3ca6a5f0 | 1302 | findInfo.psz = str; |
2bda0e17 | 1303 | |
3ca6a5f0 BP |
1304 | // ListView_FindItem() excludes the first item from search and to look |
1305 | // through all the items you need to start from -1 which is unnatural and | |
8036af01 JS |
1306 | // inconsistent with the generic version - so we adjust the index |
1307 | if (start != -1) | |
1308 | start --; | |
1309 | return ListView_FindItem(GetHwnd(), (int) start, &findInfo); | |
2bda0e17 KB |
1310 | } |
1311 | ||
1312 | // Find an item whose data matches this data, starting from the item after 'start' | |
1313 | // or the beginning if 'start' is -1. | |
debe6624 | 1314 | long wxListCtrl::FindItem(long start, long data) |
2bda0e17 | 1315 | { |
0b5efdc7 | 1316 | LV_FINDINFO findInfo; |
2bda0e17 | 1317 | |
0b5efdc7 VZ |
1318 | findInfo.flags = LVFI_PARAM; |
1319 | findInfo.lParam = data; | |
2bda0e17 | 1320 | |
edccf428 | 1321 | return ListView_FindItem(GetHwnd(), (int) start, & findInfo); |
2bda0e17 KB |
1322 | } |
1323 | ||
1324 | // Find an item nearest this position in the specified direction, starting from | |
1325 | // the item after 'start' or the beginning if 'start' is -1. | |
debe6624 | 1326 | long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction) |
2bda0e17 | 1327 | { |
0b5efdc7 | 1328 | LV_FINDINFO findInfo; |
2bda0e17 | 1329 | |
0b5efdc7 VZ |
1330 | findInfo.flags = LVFI_NEARESTXY; |
1331 | findInfo.pt.x = pt.x; | |
1332 | findInfo.pt.y = pt.y; | |
acb62b84 | 1333 | findInfo.vkDirection = VK_RIGHT; |
2bda0e17 | 1334 | |
0b5efdc7 VZ |
1335 | if ( direction == wxLIST_FIND_UP ) |
1336 | findInfo.vkDirection = VK_UP; | |
1337 | else if ( direction == wxLIST_FIND_DOWN ) | |
1338 | findInfo.vkDirection = VK_DOWN; | |
1339 | else if ( direction == wxLIST_FIND_LEFT ) | |
1340 | findInfo.vkDirection = VK_LEFT; | |
1341 | else if ( direction == wxLIST_FIND_RIGHT ) | |
1342 | findInfo.vkDirection = VK_RIGHT; | |
1343 | ||
edccf428 | 1344 | return ListView_FindItem(GetHwnd(), (int) start, & findInfo); |
2bda0e17 KB |
1345 | } |
1346 | ||
1347 | // Determines which item (if any) is at the specified point, | |
1348 | // giving details in 'flags' (see wxLIST_HITTEST_... flags above) | |
1349 | long wxListCtrl::HitTest(const wxPoint& point, int& flags) | |
1350 | { | |
1351 | LV_HITTESTINFO hitTestInfo; | |
0b5efdc7 VZ |
1352 | hitTestInfo.pt.x = (int) point.x; |
1353 | hitTestInfo.pt.y = (int) point.y; | |
2bda0e17 | 1354 | |
edccf428 | 1355 | ListView_HitTest(GetHwnd(), & hitTestInfo); |
2bda0e17 | 1356 | |
0b5efdc7 VZ |
1357 | flags = 0; |
1358 | if ( hitTestInfo.flags & LVHT_ABOVE ) | |
1359 | flags |= wxLIST_HITTEST_ABOVE; | |
1360 | if ( hitTestInfo.flags & LVHT_BELOW ) | |
1361 | flags |= wxLIST_HITTEST_BELOW; | |
1362 | if ( hitTestInfo.flags & LVHT_NOWHERE ) | |
1363 | flags |= wxLIST_HITTEST_NOWHERE; | |
1364 | if ( hitTestInfo.flags & LVHT_ONITEMICON ) | |
1365 | flags |= wxLIST_HITTEST_ONITEMICON; | |
1366 | if ( hitTestInfo.flags & LVHT_ONITEMLABEL ) | |
1367 | flags |= wxLIST_HITTEST_ONITEMLABEL; | |
1368 | if ( hitTestInfo.flags & LVHT_ONITEMSTATEICON ) | |
1369 | flags |= wxLIST_HITTEST_ONITEMSTATEICON; | |
1370 | if ( hitTestInfo.flags & LVHT_TOLEFT ) | |
1371 | flags |= wxLIST_HITTEST_TOLEFT; | |
1372 | if ( hitTestInfo.flags & LVHT_TORIGHT ) | |
1373 | flags |= wxLIST_HITTEST_TORIGHT; | |
1374 | ||
edccf428 | 1375 | return (long) hitTestInfo.iItem; |
2bda0e17 KB |
1376 | } |
1377 | ||
1378 | // Inserts an item, returning the index of the new item if successful, | |
1379 | // -1 otherwise. | |
2bda0e17 KB |
1380 | long wxListCtrl::InsertItem(wxListItem& info) |
1381 | { | |
98ec9dbe VZ |
1382 | wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") ); |
1383 | ||
0b5efdc7 VZ |
1384 | LV_ITEM item; |
1385 | wxConvertToMSWListItem(this, info, item); | |
7cf46fdb | 1386 | item.mask &= ~LVIF_PARAM; |
2bda0e17 | 1387 | |
7cf46fdb VZ |
1388 | // check wether we need to allocate our internal data |
1389 | bool needInternalData = ((info.m_mask & wxLIST_MASK_DATA) || info.HasAttributes()); | |
1390 | if (needInternalData) | |
bdc72a22 | 1391 | { |
7cf46fdb VZ |
1392 | m_AnyInternalData = TRUE; |
1393 | item.mask |= LVIF_PARAM; | |
2702ed5a | 1394 | |
7cf46fdb VZ |
1395 | // internal stucture that manages data |
1396 | wxListItemInternalData *data = new wxListItemInternalData(); | |
1397 | item.lParam = (LPARAM) data; | |
2702ed5a | 1398 | |
7cf46fdb VZ |
1399 | if (info.m_mask & wxLIST_MASK_DATA) |
1400 | data->lParam = info.m_data; | |
2702ed5a | 1401 | |
7cf46fdb VZ |
1402 | // check whether it has any custom attributes |
1403 | if ( info.HasAttributes() ) | |
1404 | { | |
1405 | // take copy of attributes | |
1406 | data->attr = new wxListItemAttr(*info.GetAttributes()); | |
bdc72a22 | 1407 | } |
7cf46fdb VZ |
1408 | }; |
1409 | ||
bdc72a22 | 1410 | |
edccf428 | 1411 | return (long) ListView_InsertItem(GetHwnd(), & item); |
2bda0e17 KB |
1412 | } |
1413 | ||
debe6624 | 1414 | long wxListCtrl::InsertItem(long index, const wxString& label) |
2bda0e17 | 1415 | { |
0b5efdc7 VZ |
1416 | wxListItem info; |
1417 | info.m_text = label; | |
1418 | info.m_mask = wxLIST_MASK_TEXT; | |
1419 | info.m_itemId = index; | |
1420 | return InsertItem(info); | |
2bda0e17 KB |
1421 | } |
1422 | ||
1423 | // Inserts an image item | |
debe6624 | 1424 | long wxListCtrl::InsertItem(long index, int imageIndex) |
2bda0e17 | 1425 | { |
0b5efdc7 VZ |
1426 | wxListItem info; |
1427 | info.m_image = imageIndex; | |
1428 | info.m_mask = wxLIST_MASK_IMAGE; | |
1429 | info.m_itemId = index; | |
1430 | return InsertItem(info); | |
2bda0e17 KB |
1431 | } |
1432 | ||
1433 | // Inserts an image/string item | |
debe6624 | 1434 | long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex) |
2bda0e17 | 1435 | { |
0b5efdc7 VZ |
1436 | wxListItem info; |
1437 | info.m_image = imageIndex; | |
1438 | info.m_text = label; | |
1439 | info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT; | |
1440 | info.m_itemId = index; | |
1441 | return InsertItem(info); | |
2bda0e17 KB |
1442 | } |
1443 | ||
1444 | // For list view mode (only), inserts a column. | |
debe6624 | 1445 | long wxListCtrl::InsertColumn(long col, wxListItem& item) |
2bda0e17 | 1446 | { |
0b5efdc7 | 1447 | LV_COLUMN lvCol; |
6f806543 | 1448 | wxConvertToMSWListCol(col, item, lvCol); |
0b5efdc7 | 1449 | |
6f806543 | 1450 | if ( !(lvCol.mask & LVCF_WIDTH) ) |
e373f51b VZ |
1451 | { |
1452 | // always give some width to the new column: this one is compatible | |
6f806543 VZ |
1453 | // with the generic version |
1454 | lvCol.mask |= LVCF_WIDTH; | |
e373f51b | 1455 | lvCol.cx = 80; |
0b5efdc7 | 1456 | } |
e373f51b | 1457 | |
6f806543 VZ |
1458 | // when we insert a column which can contain an image, we must specify this |
1459 | // flag right now as doing it later in SetColumn() has no effect | |
1460 | // | |
1461 | // we use LVCFMT_BITMAP_ON_RIGHT by default because without it there is no | |
1462 | // way to dynamically set/clear the bitmap as the column without a bitmap | |
1463 | // on the left looks ugly (there is a hole) | |
1464 | // | |
1465 | // unfortunately with my version of comctl32.dll (5.80), the left column | |
1466 | // image is always on the left and it seems that it's a "feature" - I | |
1467 | // didn't find any way to work around it in any case | |
1468 | if ( lvCol.mask & LVCF_IMAGE ) | |
1469 | { | |
1470 | lvCol.mask |= LVCF_FMT; | |
1471 | lvCol.fmt |= LVCFMT_BITMAP_ON_RIGHT; | |
1472 | } | |
2bda0e17 | 1473 | |
6f806543 | 1474 | bool success = ListView_InsertColumn(GetHwnd(), col, &lvCol) != -1; |
2bda0e17 | 1475 | if ( success ) |
e373f51b VZ |
1476 | { |
1477 | m_colCount++; | |
1478 | } | |
1479 | else | |
1480 | { | |
223d09f6 | 1481 | wxLogDebug(wxT("Failed to insert the column '%s' into listview!"), |
e373f51b VZ |
1482 | lvCol.pszText); |
1483 | } | |
1484 | ||
2bda0e17 KB |
1485 | return success; |
1486 | } | |
1487 | ||
bdc72a22 VZ |
1488 | long wxListCtrl::InsertColumn(long col, |
1489 | const wxString& heading, | |
1490 | int format, | |
1491 | int width) | |
2bda0e17 | 1492 | { |
0b5efdc7 VZ |
1493 | wxListItem item; |
1494 | item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT; | |
1495 | item.m_text = heading; | |
1496 | if ( width > -1 ) | |
1497 | { | |
1498 | item.m_mask |= wxLIST_MASK_WIDTH; | |
1499 | item.m_width = width; | |
1500 | } | |
1501 | item.m_format = format; | |
2bda0e17 | 1502 | |
0b5efdc7 | 1503 | return InsertColumn(col, item); |
2bda0e17 KB |
1504 | } |
1505 | ||
1506 | // Scrolls the list control. If in icon, small icon or report view mode, | |
1507 | // x specifies the number of pixels to scroll. If in list view mode, x | |
1508 | // specifies the number of columns to scroll. | |
1509 | // If in icon, small icon or list view mode, y specifies the number of pixels | |
1510 | // to scroll. If in report view mode, y specifies the number of lines to scroll. | |
debe6624 | 1511 | bool wxListCtrl::ScrollList(int dx, int dy) |
2bda0e17 | 1512 | { |
edccf428 | 1513 | return (ListView_Scroll(GetHwnd(), dx, dy) != 0); |
2bda0e17 KB |
1514 | } |
1515 | ||
1516 | // Sort items. | |
1517 | ||
1518 | // fn is a function which takes 3 long arguments: item1, item2, data. | |
1519 | // item1 is the long data associated with a first item (NOT the index). | |
1520 | // item2 is the long data associated with a second item (NOT the index). | |
1521 | // data is the same value as passed to SortItems. | |
1522 | // The return value is a negative number if the first item should precede the second | |
1523 | // item, a positive number of the second item should precede the first, | |
1524 | // or zero if the two items are equivalent. | |
1525 | ||
1526 | // data is arbitrary data to be passed to the sort function. | |
19230604 | 1527 | |
7cf46fdb VZ |
1528 | // Internal structures for proxying the user compare function |
1529 | // so that we can pass it the *real* user data | |
19230604 | 1530 | |
7cf46fdb VZ |
1531 | // translate lParam data and call user func |
1532 | struct wxInternalDataSort | |
19230604 | 1533 | { |
7cf46fdb VZ |
1534 | wxListCtrlCompare user_fn; |
1535 | long data; | |
1536 | }; | |
19230604 | 1537 | |
7cf46fdb | 1538 | int CALLBACK wxInternalDataCompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) |
2bda0e17 | 1539 | { |
7cf46fdb | 1540 | struct wxInternalDataSort *internalData = (struct wxInternalDataSort *) lParamSort; |
19230604 | 1541 | |
7cf46fdb VZ |
1542 | wxListItemInternalData *data1 = (wxListItemInternalData *) lParam1; |
1543 | wxListItemInternalData *data2 = (wxListItemInternalData *) lParam2; | |
19230604 | 1544 | |
7cf46fdb VZ |
1545 | long d1 = (data1 == NULL ? 0 : data1->lParam); |
1546 | long d2 = (data2 == NULL ? 0 : data2->lParam); | |
19230604 | 1547 | |
7cf46fdb | 1548 | return internalData->user_fn(d1, d2, internalData->data); |
19230604 | 1549 | |
7cf46fdb | 1550 | }; |
19230604 | 1551 | |
7cf46fdb VZ |
1552 | bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data) |
1553 | { | |
1554 | struct wxInternalDataSort internalData; | |
1555 | internalData.user_fn = fn; | |
1556 | internalData.data = data; | |
19230604 | 1557 | |
14090241 VZ |
1558 | // WPARAM cast is needed for mingw/cygwin |
1559 | if ( !ListView_SortItems(GetHwnd(), | |
1560 | wxInternalDataCompareFunc, | |
1561 | (WPARAM) &internalData) ) | |
19230604 RD |
1562 | { |
1563 | wxLogDebug(_T("ListView_SortItems() failed")); | |
1564 | ||
1565 | return FALSE; | |
1566 | } | |
1567 | ||
1568 | return TRUE; | |
2bda0e17 KB |
1569 | } |
1570 | ||
19230604 RD |
1571 | |
1572 | ||
edccf428 VZ |
1573 | // ---------------------------------------------------------------------------- |
1574 | // message processing | |
1575 | // ---------------------------------------------------------------------------- | |
1576 | ||
debe6624 | 1577 | bool wxListCtrl::MSWCommand(WXUINT cmd, WXWORD id) |
2bda0e17 | 1578 | { |
0b5efdc7 | 1579 | if (cmd == EN_UPDATE) |
acb62b84 | 1580 | { |
0b5efdc7 VZ |
1581 | wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, id); |
1582 | event.SetEventObject( this ); | |
1583 | ProcessCommand(event); | |
1584 | return TRUE; | |
acb62b84 | 1585 | } |
0b5efdc7 | 1586 | else if (cmd == EN_KILLFOCUS) |
acb62b84 | 1587 | { |
0b5efdc7 VZ |
1588 | wxCommandEvent event(wxEVT_KILL_FOCUS, id); |
1589 | event.SetEventObject( this ); | |
1590 | ProcessCommand(event); | |
1591 | return TRUE; | |
acb62b84 | 1592 | } |
edccf428 VZ |
1593 | else |
1594 | return FALSE; | |
0b5efdc7 VZ |
1595 | } |
1596 | ||
a23fd0e1 | 1597 | bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) |
0b5efdc7 | 1598 | { |
bdc72a22 VZ |
1599 | // prepare the event |
1600 | // ----------------- | |
1601 | ||
0b5efdc7 | 1602 | wxListEvent event(wxEVT_NULL, m_windowId); |
648bec3e VZ |
1603 | event.SetEventObject(this); |
1604 | ||
0b5efdc7 | 1605 | wxEventType eventType = wxEVT_NULL; |
225fe9d6 | 1606 | |
bdc72a22 | 1607 | NMHDR *nmhdr = (NMHDR *)lParam; |
225fe9d6 | 1608 | |
d1f2eb1d VZ |
1609 | // if your compiler is as broken as this, you should really change it: this |
1610 | // code is needed for normal operation! #ifdef below is only useful for | |
1611 | // automatic rebuilds which are done with a very old compiler version | |
0cf5b099 | 1612 | #ifdef HDN_BEGINTRACKA |
d1f2eb1d | 1613 | |
11358d39 VZ |
1614 | // check for messages from the header (in report view) |
1615 | HWND hwndHdr = ListView_GetHeader(GetHwnd()); | |
225fe9d6 | 1616 | |
11358d39 VZ |
1617 | // is it a message from the header? |
1618 | if ( nmhdr->hwndFrom == hwndHdr ) | |
acb62b84 | 1619 | { |
00811ff9 | 1620 | HD_NOTIFY *nmHDR = (HD_NOTIFY *)nmhdr; |
0cf5b099 | 1621 | |
11358d39 | 1622 | event.m_itemIndex = -1; |
cb0f56f9 | 1623 | |
11358d39 VZ |
1624 | switch ( nmhdr->code ) |
1625 | { | |
1626 | // yet another comctl32.dll bug: under NT/W2K it sends Unicode | |
1627 | // TRACK messages even to ANSI programs: on my system I get | |
1628 | // HDN_BEGINTRACKW and HDN_ENDTRACKA and no HDN_TRACK at all! | |
1629 | // | |
1630 | // work around is to simply catch both versions and hope that it | |
1631 | // works (why should this message exist in ANSI and Unicode is | |
1632 | // beyond me as it doesn't deal with strings at all...) | |
1633 | case HDN_BEGINTRACKA: | |
1634 | case HDN_BEGINTRACKW: | |
1635 | eventType = wxEVT_COMMAND_LIST_COL_BEGIN_DRAG; | |
1636 | // fall through | |
1637 | ||
1638 | case HDN_TRACKA: | |
1639 | case HDN_TRACKW: | |
1640 | if ( eventType == wxEVT_NULL ) | |
1641 | eventType = wxEVT_COMMAND_LIST_COL_DRAGGING; | |
1642 | // fall through | |
1643 | ||
1644 | case HDN_ENDTRACKA: | |
1645 | case HDN_ENDTRACKW: | |
1646 | if ( eventType == wxEVT_NULL ) | |
1647 | eventType = wxEVT_COMMAND_LIST_COL_END_DRAG; | |
1648 | event.m_col = nmHDR->iItem; | |
1649 | break; | |
1650 | ||
1651 | case NM_RCLICK: | |
1652 | { | |
1653 | eventType = wxEVT_COMMAND_LIST_COL_RIGHT_CLICK; | |
1654 | event.m_col = -1; | |
0b5efdc7 | 1655 | |
11358d39 VZ |
1656 | // find the column clicked: we have to search for it |
1657 | // ourselves as the notification message doesn't provide | |
1658 | // this info | |
0b5efdc7 | 1659 | |
11358d39 VZ |
1660 | // where did the click occur? |
1661 | POINT ptClick; | |
1662 | if ( !::GetCursorPos(&ptClick) ) | |
1663 | { | |
1664 | wxLogLastError(_T("GetCursorPos")); | |
1665 | } | |
0b5efdc7 | 1666 | |
11358d39 VZ |
1667 | if ( !::ScreenToClient(hwndHdr, &ptClick) ) |
1668 | { | |
1669 | wxLogLastError(_T("ScreenToClient(listctrl header)")); | |
1670 | } | |
5ea47806 | 1671 | |
11358d39 VZ |
1672 | event.m_pointDrag.x = ptClick.x; |
1673 | event.m_pointDrag.y = ptClick.y; | |
5ea47806 | 1674 | |
11358d39 | 1675 | int colCount = Header_GetItemCount(hwndHdr); |
bdc72a22 | 1676 | |
11358d39 VZ |
1677 | RECT rect; |
1678 | for ( int col = 0; col < colCount; col++ ) | |
1679 | { | |
1680 | if ( Header_GetItemRect(hwndHdr, col, &rect) ) | |
1681 | { | |
1682 | if ( ::PtInRect(&rect, ptClick) ) | |
1683 | { | |
1684 | event.m_col = col; | |
1685 | break; | |
1686 | } | |
1687 | } | |
1688 | } | |
1689 | } | |
1690 | break; | |
5ea47806 | 1691 | |
11358d39 VZ |
1692 | default: |
1693 | return wxControl::MSWOnNotify(idCtrl, lParam, result); | |
1694 | } | |
1695 | } | |
d1f2eb1d | 1696 | else |
0cf5b099 | 1697 | #endif // defined(HDN_BEGINTRACKA) |
d1f2eb1d | 1698 | if ( nmhdr->hwndFrom == GetHwnd() ) |
11358d39 VZ |
1699 | { |
1700 | // almost all messages use NM_LISTVIEW | |
1701 | NM_LISTVIEW *nmLV = (NM_LISTVIEW *)nmhdr; | |
bdc72a22 | 1702 | |
11358d39 VZ |
1703 | // this is true for almost all events |
1704 | event.m_item.m_data = nmLV->lParam; | |
bdc72a22 | 1705 | |
11358d39 VZ |
1706 | switch ( nmhdr->code ) |
1707 | { | |
1708 | case LVN_BEGINRDRAG: | |
1709 | eventType = wxEVT_COMMAND_LIST_BEGIN_RDRAG; | |
1710 | // fall through | |
7bf1474a | 1711 | |
11358d39 VZ |
1712 | case LVN_BEGINDRAG: |
1713 | if ( eventType == wxEVT_NULL ) | |
1714 | { | |
1715 | eventType = wxEVT_COMMAND_LIST_BEGIN_DRAG; | |
1716 | } | |
bdc72a22 | 1717 | |
11358d39 VZ |
1718 | event.m_itemIndex = nmLV->iItem; |
1719 | event.m_pointDrag.x = nmLV->ptAction.x; | |
1720 | event.m_pointDrag.y = nmLV->ptAction.y; | |
1721 | break; | |
1722 | ||
8c21905b VS |
1723 | // NB: we have to handle both *A and *W versions here because some |
1724 | // versions of comctl32.dll send ANSI message to an Unicode app | |
1725 | case LVN_BEGINLABELEDITA: | |
11358d39 VZ |
1726 | { |
1727 | eventType = wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT; | |
8c21905b VS |
1728 | wxLV_ITEM item(((LV_DISPINFOA *)lParam)->item); |
1729 | wxConvertFromMSWListItem(GetHwnd(), event.m_item, item); | |
1730 | event.m_itemIndex = event.m_item.m_itemId; | |
1731 | } | |
1732 | break; | |
1733 | case LVN_BEGINLABELEDITW: | |
1734 | { | |
1735 | eventType = wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT; | |
1736 | wxLV_ITEM item(((LV_DISPINFOW *)lParam)->item); | |
1737 | wxConvertFromMSWListItem(GetHwnd(), event.m_item, item); | |
1738 | event.m_itemIndex = event.m_item.m_itemId; | |
1739 | } | |
1740 | break; | |
1741 | ||
1742 | case LVN_ENDLABELEDITA: | |
1743 | { | |
1744 | eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT; | |
1745 | wxLV_ITEM item(((LV_DISPINFOA *)lParam)->item); | |
1746 | wxConvertFromMSWListItem(NULL, event.m_item, item); | |
73d8c5fd | 1747 | if ( ((LV_ITEM)item).pszText == NULL || |
8c21905b VS |
1748 | ((LV_ITEM)item).iItem == -1 ) |
1749 | return FALSE; | |
1750 | ||
1751 | event.m_itemIndex = event.m_item.m_itemId; | |
1752 | } | |
1753 | break; | |
1754 | case LVN_ENDLABELEDITW: | |
1755 | { | |
1756 | eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT; | |
1757 | wxLV_ITEM item(((LV_DISPINFOW *)lParam)->item); | |
1758 | wxConvertFromMSWListItem(NULL, event.m_item, item); | |
73d8c5fd | 1759 | if ( ((LV_ITEM)item).pszText == NULL || |
8c21905b VS |
1760 | ((LV_ITEM)item).iItem == -1 ) |
1761 | return FALSE; | |
1762 | ||
11358d39 VZ |
1763 | event.m_itemIndex = event.m_item.m_itemId; |
1764 | } | |
1765 | break; | |
edccf428 | 1766 | |
11358d39 VZ |
1767 | case LVN_COLUMNCLICK: |
1768 | eventType = wxEVT_COMMAND_LIST_COL_CLICK; | |
1769 | event.m_itemIndex = -1; | |
1770 | event.m_col = nmLV->iSubItem; | |
1771 | break; | |
bdc72a22 | 1772 | |
11358d39 VZ |
1773 | case LVN_DELETEALLITEMS: |
1774 | eventType = wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS; | |
1775 | event.m_itemIndex = -1; | |
11358d39 VZ |
1776 | break; |
1777 | ||
1778 | case LVN_DELETEITEM: | |
1779 | eventType = wxEVT_COMMAND_LIST_DELETE_ITEM; | |
225fe9d6 | 1780 | event.m_itemIndex = nmLV->iItem; |
7cf46fdb | 1781 | // delete the assoicated internal data |
6149de71 | 1782 | wxDeleteInternalData(this, nmLV->iItem); |
11358d39 VZ |
1783 | break; |
1784 | ||
11358d39 VZ |
1785 | case LVN_SETDISPINFO: |
1786 | { | |
1787 | eventType = wxEVT_COMMAND_LIST_SET_INFO; | |
1788 | LV_DISPINFO *info = (LV_DISPINFO *)lParam; | |
1789 | wxConvertFromMSWListItem(GetHwnd(), event.m_item, info->item); | |
1790 | } | |
1791 | break; | |
1792 | ||
1793 | case LVN_INSERTITEM: | |
1794 | eventType = wxEVT_COMMAND_LIST_INSERT_ITEM; | |
225fe9d6 | 1795 | event.m_itemIndex = nmLV->iItem; |
11358d39 | 1796 | break; |
edccf428 | 1797 | |
11358d39 | 1798 | case LVN_ITEMCHANGED: |
648bec3e VZ |
1799 | // we translate this catch all message into more interesting |
1800 | // (and more easy to process) wxWindows events | |
1801 | ||
1802 | // first of all, we deal with the state change events only | |
1803 | if ( nmLV->uChanged & LVIF_STATE ) | |
11358d39 | 1804 | { |
648bec3e VZ |
1805 | // temp vars for readability |
1806 | const UINT stOld = nmLV->uOldState; | |
1807 | const UINT stNew = nmLV->uNewState; | |
1808 | ||
1809 | // has the focus changed? | |
1810 | if ( !(stOld & LVIS_FOCUSED) && (stNew & LVIS_FOCUSED) ) | |
1811 | { | |
1812 | eventType = wxEVT_COMMAND_LIST_ITEM_FOCUSED; | |
1813 | event.m_itemIndex = nmLV->iItem; | |
1814 | } | |
1815 | ||
1816 | if ( (stNew & LVIS_SELECTED) != (stOld & LVIS_SELECTED) ) | |
1817 | { | |
1818 | if ( eventType != wxEVT_NULL ) | |
1819 | { | |
1820 | // focus and selection have both changed: send the | |
1821 | // focus event from here and the selection one | |
1822 | // below | |
1823 | event.SetEventType(eventType); | |
1824 | (void)GetEventHandler()->ProcessEvent(event); | |
1825 | } | |
1826 | else // no focus event to send | |
1827 | { | |
1828 | // then need to set m_itemIndex as it wasn't done | |
1829 | // above | |
1830 | event.m_itemIndex = nmLV->iItem; | |
1831 | } | |
1832 | ||
1833 | eventType = stNew & LVIS_SELECTED | |
1834 | ? wxEVT_COMMAND_LIST_ITEM_SELECTED | |
1835 | : wxEVT_COMMAND_LIST_ITEM_DESELECTED; | |
1836 | } | |
edccf428 | 1837 | } |
648bec3e VZ |
1838 | |
1839 | if ( eventType == wxEVT_NULL ) | |
edccf428 | 1840 | { |
648bec3e | 1841 | // not an interesting event for us |
11358d39 | 1842 | return FALSE; |
edccf428 | 1843 | } |
648bec3e | 1844 | |
11358d39 | 1845 | break; |
225fe9d6 | 1846 | |
11358d39 VZ |
1847 | case LVN_KEYDOWN: |
1848 | { | |
1849 | LV_KEYDOWN *info = (LV_KEYDOWN *)lParam; | |
1850 | WORD wVKey = info->wVKey; | |
1851 | ||
1852 | // get the current selection | |
1853 | long lItem = GetNextItem(-1, | |
1854 | wxLIST_NEXT_ALL, | |
1855 | wxLIST_STATE_SELECTED); | |
1856 | ||
1857 | // <Enter> or <Space> activate the selected item if any (but | |
1858 | // not with Shift and/or Ctrl as then they have a predefined | |
1859 | // meaning for the list view) | |
1860 | if ( lItem != -1 && | |
1861 | (wVKey == VK_RETURN || wVKey == VK_SPACE) && | |
1862 | !(wxIsShiftDown() || wxIsCtrlDown()) ) | |
1863 | { | |
1864 | eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED; | |
1865 | } | |
1866 | else | |
1867 | { | |
1868 | eventType = wxEVT_COMMAND_LIST_KEY_DOWN; | |
185d0094 VZ |
1869 | |
1870 | // wxCharCodeMSWToWX() returns 0 if the key is an ASCII | |
1871 | // value which should be used as is | |
1872 | int code = wxCharCodeMSWToWX(wVKey); | |
1873 | event.m_code = code ? code : wVKey; | |
11358d39 | 1874 | } |
7db91489 | 1875 | |
11358d39 VZ |
1876 | event.m_itemIndex = |
1877 | event.m_item.m_itemId = lItem; | |
1878 | ||
1879 | if ( lItem != -1 ) | |
1880 | { | |
1881 | // fill the other fields too | |
1882 | event.m_item.m_text = GetItemText(lItem); | |
1883 | event.m_item.m_data = GetItemData(lItem); | |
1884 | } | |
1885 | } | |
1886 | break; | |
1887 | ||
1888 | case NM_DBLCLK: | |
1889 | // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do | |
1890 | // anything else | |
1891 | if ( wxControl::MSWOnNotify(idCtrl, lParam, result) ) | |
f6bcfd97 | 1892 | { |
11358d39 | 1893 | return TRUE; |
f6bcfd97 | 1894 | } |
edccf428 | 1895 | |
11358d39 VZ |
1896 | // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event |
1897 | // if it happened on an item (and not on empty place) | |
1898 | if ( nmLV->iItem == -1 ) | |
1899 | { | |
1900 | // not on item | |
1901 | return FALSE; | |
1902 | } | |
edccf428 | 1903 | |
11358d39 VZ |
1904 | eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED; |
1905 | event.m_itemIndex = nmLV->iItem; | |
1906 | event.m_item.m_text = GetItemText(nmLV->iItem); | |
1907 | event.m_item.m_data = GetItemData(nmLV->iItem); | |
1908 | break; | |
225fe9d6 | 1909 | |
11358d39 | 1910 | case NM_RCLICK: |
225fe9d6 VZ |
1911 | // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(), |
1912 | // don't do anything else | |
1913 | if ( wxControl::MSWOnNotify(idCtrl, lParam, result) ) | |
1914 | { | |
1915 | return TRUE; | |
1916 | } | |
cb0f56f9 | 1917 | |
225fe9d6 VZ |
1918 | // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event |
1919 | LV_HITTESTINFO lvhti; | |
1920 | wxZeroMemory(lvhti); | |
11c7d5b6 | 1921 | |
225fe9d6 VZ |
1922 | ::GetCursorPos(&(lvhti.pt)); |
1923 | ::ScreenToClient(GetHwnd(),&(lvhti.pt)); | |
1924 | if ( ListView_HitTest(GetHwnd(),&lvhti) != -1 ) | |
cb0f56f9 | 1925 | { |
225fe9d6 VZ |
1926 | if ( lvhti.flags & LVHT_ONITEM ) |
1927 | { | |
1928 | eventType = wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK; | |
1929 | event.m_itemIndex = lvhti.iItem; | |
a1f79c1e VZ |
1930 | event.m_pointDrag.x = lvhti.pt.x; |
1931 | event.m_pointDrag.y = lvhti.pt.y; | |
225fe9d6 | 1932 | } |
cb0f56f9 | 1933 | } |
11358d39 | 1934 | break; |
bdc72a22 | 1935 | |
bf9b6266 | 1936 | #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \ |
11358d39 VZ |
1937 | && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) ) |
1938 | case NM_CUSTOMDRAW: | |
1939 | *result = OnCustomDraw(lParam); | |
63166611 | 1940 | |
11358d39 | 1941 | return TRUE; |
6ecfe2ac | 1942 | #endif // _WIN32_IE >= 0x300 |
0b5efdc7 | 1943 | |
11358d39 VZ |
1944 | case LVN_ODCACHEHINT: |
1945 | { | |
1946 | const NM_CACHEHINT *cacheHint = (NM_CACHEHINT *)lParam; | |
614391dc | 1947 | |
11358d39 | 1948 | eventType = wxEVT_COMMAND_LIST_CACHE_HINT; |
e623926d | 1949 | |
11358d39 VZ |
1950 | // we get some really stupid cache hints like ones for items in |
1951 | // range 0..0 for an empty control or, after deleting an item, | |
1952 | // for items in invalid range - filter this garbage out | |
1953 | if ( cacheHint->iFrom < cacheHint->iTo ) | |
1954 | { | |
1955 | event.m_oldItemIndex = cacheHint->iFrom; | |
e623926d | 1956 | |
11358d39 VZ |
1957 | long iMax = GetItemCount(); |
1958 | event.m_itemIndex = cacheHint->iTo < iMax ? cacheHint->iTo | |
1959 | : iMax - 1; | |
1960 | } | |
1961 | else | |
1962 | { | |
1963 | return FALSE; | |
1964 | } | |
e623926d | 1965 | } |
11358d39 | 1966 | break; |
614391dc | 1967 | |
11358d39 VZ |
1968 | case LVN_GETDISPINFO: |
1969 | if ( IsVirtual() ) | |
1970 | { | |
1971 | LV_DISPINFO *info = (LV_DISPINFO *)lParam; | |
98ec9dbe | 1972 | |
11358d39 VZ |
1973 | LV_ITEM& lvi = info->item; |
1974 | long item = lvi.iItem; | |
98ec9dbe | 1975 | |
11358d39 VZ |
1976 | if ( lvi.mask & LVIF_TEXT ) |
1977 | { | |
1978 | wxString text = OnGetItemText(item, lvi.iSubItem); | |
1979 | wxStrncpy(lvi.pszText, text, lvi.cchTextMax); | |
1980 | } | |
98ec9dbe | 1981 | |
244531bc | 1982 | #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \ |
5145e34f | 1983 | && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) ) |
11358d39 VZ |
1984 | if ( lvi.mask & LVIF_IMAGE ) |
1985 | { | |
1986 | lvi.iImage = OnGetItemImage(item); | |
1987 | } | |
244531bc | 1988 | #endif |
98ec9dbe | 1989 | |
11358d39 VZ |
1990 | // a little dose of healthy paranoia: as we never use |
1991 | // LVM_SETCALLBACKMASK we're not supposed to get these ones | |
1992 | wxASSERT_MSG( !(lvi.mask & LVIF_STATE), | |
1993 | _T("we don't support state callbacks yet!") ); | |
98ec9dbe | 1994 | |
11358d39 VZ |
1995 | return TRUE; |
1996 | } | |
1997 | // fall through | |
98ec9dbe | 1998 | |
11358d39 VZ |
1999 | default: |
2000 | return wxControl::MSWOnNotify(idCtrl, lParam, result); | |
2001 | } | |
2002 | } | |
2003 | else | |
2004 | { | |
2005 | // where did this one come from? | |
2006 | return FALSE; | |
acb62b84 VZ |
2007 | } |
2008 | ||
bdc72a22 VZ |
2009 | // process the event |
2010 | // ----------------- | |
2011 | ||
0b5efdc7 | 2012 | event.SetEventType(eventType); |
acb62b84 | 2013 | |
0b5efdc7 VZ |
2014 | if ( !GetEventHandler()->ProcessEvent(event) ) |
2015 | return FALSE; | |
acb62b84 | 2016 | |
bdc72a22 VZ |
2017 | // post processing |
2018 | // --------------- | |
2019 | ||
225fe9d6 | 2020 | switch ( nmhdr->code ) |
acb62b84 | 2021 | { |
6932a32c VZ |
2022 | case LVN_DELETEALLITEMS: |
2023 | // always return TRUE to suppress all additional LVN_DELETEITEM | |
2024 | // notifications - this makes deleting all items from a list ctrl | |
2025 | // much faster | |
2026 | *result = TRUE; | |
2027 | ||
2028 | return TRUE; | |
2029 | ||
8c21905b VS |
2030 | case LVN_ENDLABELEDITA: |
2031 | case LVN_ENDLABELEDITW: | |
614391dc VZ |
2032 | // logic here is inversed compared to all the other messages |
2033 | *result = event.IsAllowed(); | |
2034 | ||
2035 | return TRUE; | |
acb62b84 | 2036 | } |
acb62b84 | 2037 | |
0b5efdc7 | 2038 | *result = !event.IsAllowed(); |
fd3f686c | 2039 | |
0b5efdc7 | 2040 | return TRUE; |
2bda0e17 KB |
2041 | } |
2042 | ||
63166611 VZ |
2043 | #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 |
2044 | ||
2045 | WXLPARAM wxListCtrl::OnCustomDraw(WXLPARAM lParam) | |
2046 | { | |
2047 | LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam; | |
2048 | NMCUSTOMDRAW& nmcd = lplvcd->nmcd; | |
2049 | switch ( nmcd.dwDrawStage ) | |
2050 | { | |
2051 | case CDDS_PREPAINT: | |
2052 | // if we've got any items with non standard attributes, | |
2053 | // notify us before painting each item | |
2054 | // | |
2055 | // for virtual controls, always suppose that we have attributes as | |
2056 | // there is no way to check for this | |
2057 | return IsVirtual() || m_hasAnyAttr ? CDRF_NOTIFYITEMDRAW | |
2058 | : CDRF_DODEFAULT; | |
2059 | ||
2060 | case CDDS_ITEMPREPAINT: | |
2061 | { | |
2062 | size_t item = (size_t)nmcd.dwItemSpec; | |
a7f560a2 VZ |
2063 | if ( item >= (size_t)GetItemCount() ) |
2064 | { | |
2065 | // we get this message with item == 0 for an empty control, | |
2066 | // we must ignore it as calling OnGetItemAttr() would be | |
2067 | // wrong | |
2068 | return CDRF_DODEFAULT; | |
2069 | } | |
2070 | ||
63166611 VZ |
2071 | wxListItemAttr *attr = |
2072 | IsVirtual() ? OnGetItemAttr(item) | |
6149de71 | 2073 | : wxGetInternalDataAttr(this, item); |
63166611 VZ |
2074 | |
2075 | if ( !attr ) | |
2076 | { | |
2077 | // nothing to do for this item | |
2078 | return CDRF_DODEFAULT; | |
2079 | } | |
2080 | ||
2081 | HFONT hFont; | |
2082 | wxColour colText, colBack; | |
2083 | if ( attr->HasFont() ) | |
2084 | { | |
2085 | wxFont font = attr->GetFont(); | |
2086 | hFont = (HFONT)font.GetResourceHandle(); | |
2087 | } | |
2088 | else | |
2089 | { | |
2090 | hFont = 0; | |
2091 | } | |
2092 | ||
2093 | if ( attr->HasTextColour() ) | |
2094 | { | |
2095 | colText = attr->GetTextColour(); | |
2096 | } | |
2097 | else | |
2098 | { | |
2099 | colText = GetTextColour(); | |
2100 | } | |
2101 | ||
2102 | if ( attr->HasBackgroundColour() ) | |
2103 | { | |
2104 | colBack = attr->GetBackgroundColour(); | |
2105 | } | |
2106 | else | |
2107 | { | |
2108 | colBack = GetBackgroundColour(); | |
2109 | } | |
2110 | ||
2111 | lplvcd->clrText = wxColourToRGB(colText); | |
2112 | lplvcd->clrTextBk = wxColourToRGB(colBack); | |
2113 | ||
2114 | // note that if we wanted to set colours for | |
2115 | // individual columns (subitems), we would have | |
2116 | // returned CDRF_NOTIFYSUBITEMREDRAW from here | |
2117 | if ( hFont ) | |
2118 | { | |
2119 | ::SelectObject(nmcd.hdc, hFont); | |
2120 | ||
2121 | return CDRF_NEWFONT; | |
2122 | } | |
2123 | } | |
2124 | // fall through to return CDRF_DODEFAULT | |
2125 | ||
2126 | default: | |
2127 | return CDRF_DODEFAULT; | |
2128 | } | |
2129 | } | |
2130 | ||
2131 | #endif // NM_CUSTOMDRAW supported | |
2132 | ||
2702ed5a JS |
2133 | // Necessary for drawing hrules and vrules, if specified |
2134 | void wxListCtrl::OnPaint(wxPaintEvent& event) | |
2135 | { | |
2136 | wxPaintDC dc(this); | |
2137 | ||
2138 | wxControl::OnPaint(event); | |
2139 | ||
2140 | // Reset the device origin since it may have been set | |
2141 | dc.SetDeviceOrigin(0, 0); | |
2142 | ||
2143 | bool drawHRules = ((GetWindowStyle() & wxLC_HRULES) != 0); | |
2144 | bool drawVRules = ((GetWindowStyle() & wxLC_VRULES) != 0); | |
2145 | ||
2146 | if (!drawHRules && !drawVRules) | |
2147 | return; | |
2148 | if ((GetWindowStyle() & wxLC_REPORT) == 0) | |
2149 | return; | |
2150 | ||
a756f210 | 2151 | wxPen pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID); |
2702ed5a JS |
2152 | dc.SetPen(pen); |
2153 | dc.SetBrush(* wxTRANSPARENT_BRUSH); | |
2154 | ||
2155 | wxSize clientSize = GetClientSize(); | |
2156 | wxRect itemRect; | |
2157 | int cy=0; | |
2158 | ||
2702ed5a JS |
2159 | int itemCount = GetItemCount(); |
2160 | int i; | |
625cb8c0 | 2161 | if (drawHRules) |
2702ed5a | 2162 | { |
6443de02 RD |
2163 | long top = GetTopItem(); |
2164 | for (i = top; i < top + GetCountPerPage() + 1; i++) | |
2702ed5a | 2165 | { |
625cb8c0 | 2166 | if (GetItemRect(i, itemRect)) |
ca286917 | 2167 | { |
625cb8c0 RD |
2168 | cy = itemRect.GetTop(); |
2169 | if (i != 0) // Don't draw the first one | |
2170 | { | |
2171 | dc.DrawLine(0, cy, clientSize.x, cy); | |
2172 | } | |
2173 | // Draw last line | |
2cefcb34 | 2174 | if (i == itemCount - 1) |
625cb8c0 RD |
2175 | { |
2176 | cy = itemRect.GetBottom(); | |
2177 | dc.DrawLine(0, cy, clientSize.x, cy); | |
2178 | } | |
2702ed5a JS |
2179 | } |
2180 | } | |
2181 | } | |
2cefcb34 | 2182 | i = itemCount - 1; |
2702ed5a JS |
2183 | if (drawVRules && (i > -1)) |
2184 | { | |
2185 | wxRect firstItemRect; | |
2186 | GetItemRect(0, firstItemRect); | |
2187 | ||
2188 | if (GetItemRect(i, itemRect)) | |
2189 | { | |
2190 | int col; | |
2191 | int x = itemRect.GetX(); | |
2192 | for (col = 0; col < GetColumnCount(); col++) | |
2193 | { | |
2194 | int colWidth = GetColumnWidth(col); | |
2195 | x += colWidth ; | |
2196 | dc.DrawLine(x, firstItemRect.GetY() - 2, x, itemRect.GetBottom()); | |
2197 | } | |
2198 | } | |
2199 | } | |
2200 | } | |
2201 | ||
98ec9dbe VZ |
2202 | // ---------------------------------------------------------------------------- |
2203 | // virtual list controls | |
2204 | // ---------------------------------------------------------------------------- | |
2205 | ||
d699f48b | 2206 | wxString wxListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const |
98ec9dbe VZ |
2207 | { |
2208 | // this is a pure virtual function, in fact - which is not really pure | |
2209 | // because the controls which are not virtual don't need to implement it | |
2210 | wxFAIL_MSG( _T("not supposed to be called") ); | |
2211 | ||
2212 | return wxEmptyString; | |
2213 | } | |
2214 | ||
d699f48b | 2215 | int wxListCtrl::OnGetItemImage(long WXUNUSED(item)) const |
98ec9dbe VZ |
2216 | { |
2217 | // same as above | |
2218 | wxFAIL_MSG( _T("not supposed to be called") ); | |
2219 | ||
2220 | return -1; | |
2221 | } | |
2222 | ||
d699f48b | 2223 | wxListItemAttr *wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)) const |
6c02c329 | 2224 | { |
63166611 | 2225 | wxASSERT_MSG( item >= 0 && item < GetItemCount(), |
6c02c329 VZ |
2226 | _T("invalid item index in OnGetItemAttr()") ); |
2227 | ||
2228 | // no attributes by default | |
2229 | return NULL; | |
2230 | } | |
2231 | ||
98ec9dbe VZ |
2232 | void wxListCtrl::SetItemCount(long count) |
2233 | { | |
2234 | wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") ); | |
2235 | ||
2236 | if ( !::SendMessage(GetHwnd(), LVM_SETITEMCOUNT, (WPARAM)count, 0) ) | |
2237 | { | |
2238 | wxLogLastError(_T("ListView_SetItemCount")); | |
2239 | } | |
2240 | } | |
2241 | ||
a7f560a2 VZ |
2242 | void wxListCtrl::RefreshItem(long item) |
2243 | { | |
2d33aec9 VZ |
2244 | // strangely enough, ListView_Update() results in much more flicker here |
2245 | // than a dumb Refresh() -- why? | |
2246 | #if 0 | |
a7f560a2 VZ |
2247 | if ( !ListView_Update(GetHwnd(), item) ) |
2248 | { | |
2249 | wxLogLastError(_T("ListView_Update")); | |
2250 | } | |
2d33aec9 VZ |
2251 | #else // 1 |
2252 | wxRect rect; | |
2253 | GetItemRect(item, rect); | |
2254 | RefreshRect(rect); | |
2255 | #endif // 0/1 | |
a7f560a2 VZ |
2256 | } |
2257 | ||
2258 | void wxListCtrl::RefreshItems(long itemFrom, long itemTo) | |
2259 | { | |
d0debf52 VZ |
2260 | wxRect rect1, rect2; |
2261 | GetItemRect(itemFrom, rect1); | |
2262 | GetItemRect(itemTo, rect2); | |
2263 | ||
2264 | wxRect rect = rect1; | |
2265 | rect.height = rect2.GetBottom() - rect1.GetTop(); | |
2266 | ||
2267 | RefreshRect(rect); | |
a7f560a2 VZ |
2268 | } |
2269 | ||
6149de71 | 2270 | static wxListItemInternalData *wxGetInternalData(HWND hwnd, long itemId) |
7cf46fdb VZ |
2271 | { |
2272 | LV_ITEM it; | |
2273 | it.mask = LVIF_PARAM; | |
2274 | it.iItem = itemId; | |
2275 | ||
2276 | bool success = ListView_GetItem(hwnd, &it) != 0; | |
2277 | if (success) | |
2278 | return (wxListItemInternalData *) it.lParam; | |
2279 | else | |
2280 | return NULL; | |
2281 | }; | |
2282 | ||
6149de71 | 2283 | static wxListItemInternalData *wxGetInternalData(wxListCtrl *ctl, long itemId) |
7cf46fdb | 2284 | { |
6149de71 | 2285 | return wxGetInternalData((HWND) ctl->GetHWND(), itemId); |
7cf46fdb VZ |
2286 | }; |
2287 | ||
6149de71 | 2288 | static wxListItemAttr *wxGetInternalDataAttr(wxListCtrl *ctl, long itemId) |
7cf46fdb | 2289 | { |
6149de71 | 2290 | wxListItemInternalData *data = wxGetInternalData(ctl, itemId); |
7cf46fdb VZ |
2291 | if (data) |
2292 | return data->attr; | |
2293 | else | |
2294 | return NULL; | |
2295 | }; | |
2296 | ||
6149de71 RD |
2297 | static void wxDeleteInternalData(wxListCtrl* ctl, long itemId) |
2298 | { | |
2299 | wxListItemInternalData *data = wxGetInternalData(ctl, itemId); | |
2300 | if (data) | |
2301 | { | |
2302 | delete data; | |
2303 | LV_ITEM item; | |
2304 | memset(&item, 0, sizeof(item)); | |
2305 | item.iItem = itemId; | |
2306 | item.mask = LVIF_PARAM; | |
2307 | item.lParam = (LPARAM) 0; | |
2308 | ListView_SetItem((HWND)ctl->GetHWND(), &item); | |
2309 | } | |
2310 | } | |
7cf46fdb | 2311 | |
8dff2b5c VZ |
2312 | static void wxConvertFromMSWListItem(HWND hwndListCtrl, |
2313 | wxListItem& info, | |
2314 | LV_ITEM& lvItem) | |
2bda0e17 | 2315 | { |
73d8c5fd | 2316 | wxListItemInternalData *internaldata = |
7cf46fdb VZ |
2317 | (wxListItemInternalData *) lvItem.lParam; |
2318 | ||
2319 | if (internaldata) | |
2320 | info.m_data = internaldata->lParam; | |
2321 | ||
0b5efdc7 VZ |
2322 | info.m_mask = 0; |
2323 | info.m_state = 0; | |
2324 | info.m_stateMask = 0; | |
2325 | info.m_itemId = lvItem.iItem; | |
acb62b84 | 2326 | |
0b5efdc7 | 2327 | long oldMask = lvItem.mask; |
acb62b84 | 2328 | |
0b5efdc7 | 2329 | bool needText = FALSE; |
8dff2b5c | 2330 | if (hwndListCtrl != 0) |
acb62b84 | 2331 | { |
0b5efdc7 VZ |
2332 | if ( lvItem.mask & LVIF_TEXT ) |
2333 | needText = FALSE; | |
2334 | else | |
2335 | needText = TRUE; | |
acb62b84 | 2336 | |
0b5efdc7 VZ |
2337 | if ( needText ) |
2338 | { | |
837e5743 | 2339 | lvItem.pszText = new wxChar[513]; |
0b5efdc7 VZ |
2340 | lvItem.cchTextMax = 512; |
2341 | } | |
edccf428 | 2342 | lvItem.mask |= LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM; |
8dff2b5c | 2343 | ::SendMessage(hwndListCtrl, LVM_GETITEM, 0, (LPARAM)& lvItem); |
0b5efdc7 | 2344 | } |
acb62b84 | 2345 | |
0b5efdc7 | 2346 | if ( lvItem.mask & LVIF_STATE ) |
acb62b84 | 2347 | { |
0b5efdc7 VZ |
2348 | info.m_mask |= wxLIST_MASK_STATE; |
2349 | ||
2350 | if ( lvItem.stateMask & LVIS_CUT) | |
2351 | { | |
edccf428 | 2352 | info.m_stateMask |= wxLIST_STATE_CUT; |
0b5efdc7 | 2353 | if ( lvItem.state & LVIS_CUT ) |
edccf428 | 2354 | info.m_state |= wxLIST_STATE_CUT; |
0b5efdc7 VZ |
2355 | } |
2356 | if ( lvItem.stateMask & LVIS_DROPHILITED) | |
2357 | { | |
edccf428 | 2358 | info.m_stateMask |= wxLIST_STATE_DROPHILITED; |
0b5efdc7 | 2359 | if ( lvItem.state & LVIS_DROPHILITED ) |
edccf428 | 2360 | info.m_state |= wxLIST_STATE_DROPHILITED; |
0b5efdc7 VZ |
2361 | } |
2362 | if ( lvItem.stateMask & LVIS_FOCUSED) | |
2363 | { | |
edccf428 | 2364 | info.m_stateMask |= wxLIST_STATE_FOCUSED; |
0b5efdc7 | 2365 | if ( lvItem.state & LVIS_FOCUSED ) |
edccf428 | 2366 | info.m_state |= wxLIST_STATE_FOCUSED; |
0b5efdc7 VZ |
2367 | } |
2368 | if ( lvItem.stateMask & LVIS_SELECTED) | |
2369 | { | |
edccf428 | 2370 | info.m_stateMask |= wxLIST_STATE_SELECTED; |
0b5efdc7 | 2371 | if ( lvItem.state & LVIS_SELECTED ) |
edccf428 | 2372 | info.m_state |= wxLIST_STATE_SELECTED; |
0b5efdc7 | 2373 | } |
acb62b84 | 2374 | } |
0b5efdc7 VZ |
2375 | |
2376 | if ( lvItem.mask & LVIF_TEXT ) | |
acb62b84 | 2377 | { |
0b5efdc7 VZ |
2378 | info.m_mask |= wxLIST_MASK_TEXT; |
2379 | info.m_text = lvItem.pszText; | |
acb62b84 | 2380 | } |
0b5efdc7 | 2381 | if ( lvItem.mask & LVIF_IMAGE ) |
acb62b84 | 2382 | { |
0b5efdc7 VZ |
2383 | info.m_mask |= wxLIST_MASK_IMAGE; |
2384 | info.m_image = lvItem.iImage; | |
acb62b84 | 2385 | } |
0b5efdc7 VZ |
2386 | if ( lvItem.mask & LVIF_PARAM ) |
2387 | info.m_mask |= wxLIST_MASK_DATA; | |
2388 | if ( lvItem.mask & LVIF_DI_SETITEM ) | |
2389 | info.m_mask |= wxLIST_SET_ITEM; | |
2390 | info.m_col = lvItem.iSubItem; | |
2391 | ||
2392 | if (needText) | |
acb62b84 | 2393 | { |
0b5efdc7 VZ |
2394 | if (lvItem.pszText) |
2395 | delete[] lvItem.pszText; | |
acb62b84 | 2396 | } |
edccf428 | 2397 | lvItem.mask = oldMask; |
2bda0e17 KB |
2398 | } |
2399 | ||
8dff2b5c VZ |
2400 | static void wxConvertToMSWFlags(long state, long stateMask, LV_ITEM& lvItem) |
2401 | { | |
2402 | if (stateMask & wxLIST_STATE_CUT) | |
2403 | { | |
2404 | lvItem.stateMask |= LVIS_CUT; | |
2405 | if (state & wxLIST_STATE_CUT) | |
2406 | lvItem.state |= LVIS_CUT; | |
2407 | } | |
2408 | if (stateMask & wxLIST_STATE_DROPHILITED) | |
2409 | { | |
2410 | lvItem.stateMask |= LVIS_DROPHILITED; | |
2411 | if (state & wxLIST_STATE_DROPHILITED) | |
2412 | lvItem.state |= LVIS_DROPHILITED; | |
2413 | } | |
2414 | if (stateMask & wxLIST_STATE_FOCUSED) | |
2415 | { | |
2416 | lvItem.stateMask |= LVIS_FOCUSED; | |
2417 | if (state & wxLIST_STATE_FOCUSED) | |
2418 | lvItem.state |= LVIS_FOCUSED; | |
2419 | } | |
2420 | if (stateMask & wxLIST_STATE_SELECTED) | |
2421 | { | |
2422 | lvItem.stateMask |= LVIS_SELECTED; | |
2423 | if (state & wxLIST_STATE_SELECTED) | |
2424 | lvItem.state |= LVIS_SELECTED; | |
2425 | } | |
2426 | } | |
2427 | ||
2428 | static void wxConvertToMSWListItem(const wxListCtrl *ctrl, | |
2429 | const wxListItem& info, | |
2430 | LV_ITEM& lvItem) | |
2bda0e17 | 2431 | { |
edccf428 | 2432 | lvItem.iItem = (int) info.m_itemId; |
acb62b84 | 2433 | |
edccf428 | 2434 | lvItem.iImage = info.m_image; |
0b5efdc7 VZ |
2435 | lvItem.stateMask = 0; |
2436 | lvItem.state = 0; | |
2437 | lvItem.mask = 0; | |
2438 | lvItem.iSubItem = info.m_col; | |
acb62b84 | 2439 | |
0b5efdc7 | 2440 | if (info.m_mask & wxLIST_MASK_STATE) |
acb62b84 | 2441 | { |
edccf428 | 2442 | lvItem.mask |= LVIF_STATE; |
8dff2b5c VZ |
2443 | |
2444 | wxConvertToMSWFlags(info.m_state, info.m_stateMask, lvItem); | |
acb62b84 | 2445 | } |
acb62b84 | 2446 | |
0b5efdc7 | 2447 | if (info.m_mask & wxLIST_MASK_TEXT) |
acb62b84 | 2448 | { |
edccf428 | 2449 | lvItem.mask |= LVIF_TEXT; |
0b5efdc7 VZ |
2450 | if ( ctrl->GetWindowStyleFlag() & wxLC_USER_TEXT ) |
2451 | { | |
2452 | lvItem.pszText = LPSTR_TEXTCALLBACK; | |
2453 | } | |
2454 | else | |
2455 | { | |
e421922f VZ |
2456 | // pszText is not const, hence the cast |
2457 | lvItem.pszText = (wxChar *)info.m_text.c_str(); | |
0b5efdc7 VZ |
2458 | if ( lvItem.pszText ) |
2459 | lvItem.cchTextMax = info.m_text.Length(); | |
2460 | else | |
2461 | lvItem.cchTextMax = 0; | |
2462 | } | |
acb62b84 | 2463 | } |
0b5efdc7 | 2464 | if (info.m_mask & wxLIST_MASK_IMAGE) |
edccf428 | 2465 | lvItem.mask |= LVIF_IMAGE; |
2bda0e17 KB |
2466 | } |
2467 | ||
574c939e | 2468 | static void wxConvertToMSWListCol(int WXUNUSED(col), const wxListItem& item, |
6f806543 VZ |
2469 | LV_COLUMN& lvCol) |
2470 | { | |
2471 | wxZeroMemory(lvCol); | |
2472 | ||
2473 | if ( item.m_mask & wxLIST_MASK_TEXT ) | |
2474 | { | |
2475 | lvCol.mask |= LVCF_TEXT; | |
2476 | lvCol.pszText = (wxChar *)item.m_text.c_str(); // cast is safe | |
2477 | } | |
2478 | ||
2479 | if ( item.m_mask & wxLIST_MASK_FORMAT ) | |
2480 | { | |
2481 | lvCol.mask |= LVCF_FMT; | |
2482 | ||
2483 | if ( item.m_format == wxLIST_FORMAT_LEFT ) | |
2484 | lvCol.fmt = LVCFMT_LEFT; | |
2485 | else if ( item.m_format == wxLIST_FORMAT_RIGHT ) | |
2486 | lvCol.fmt = LVCFMT_RIGHT; | |
2487 | else if ( item.m_format == wxLIST_FORMAT_CENTRE ) | |
2488 | lvCol.fmt = LVCFMT_CENTER; | |
2489 | } | |
2490 | ||
2491 | if ( item.m_mask & wxLIST_MASK_WIDTH ) | |
2492 | { | |
2493 | lvCol.mask |= LVCF_WIDTH; | |
2494 | if ( item.m_width == wxLIST_AUTOSIZE) | |
2495 | lvCol.cx = LVSCW_AUTOSIZE; | |
2496 | else if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER) | |
2497 | lvCol.cx = LVSCW_AUTOSIZE_USEHEADER; | |
2498 | else | |
2499 | lvCol.cx = item.m_width; | |
2500 | } | |
2501 | ||
244531bc | 2502 | #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \ |
5145e34f | 2503 | && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) ) |
6f806543 VZ |
2504 | if ( item.m_mask & wxLIST_MASK_IMAGE ) |
2505 | { | |
2506 | if ( wxTheApp->GetComCtl32Version() >= 470 ) | |
2507 | { | |
2508 | lvCol.mask |= LVCF_IMAGE; | |
2509 | lvCol.iImage = item.m_image; | |
2510 | } | |
2511 | //else: it doesn't support item images anyhow | |
2512 | } | |
244531bc | 2513 | #endif |
6f806543 VZ |
2514 | } |
2515 | ||
1e6feb95 | 2516 | #endif // wxUSE_LISTCTRL |