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