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