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