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