]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: listctrl.cpp | |
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 | ||
9f303149 VZ |
32 | #ifdef __WIN95__ |
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 | ||
c42404a5 | 48 | #ifdef __GNUWIN32_OLD__ |
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 | ||
edccf428 VZ |
67 | // ---------------------------------------------------------------------------- |
68 | // private functions | |
69 | // ---------------------------------------------------------------------------- | |
2bda0e17 KB |
70 | |
71 | static void wxConvertToMSWListItem(const wxListCtrl *ctrl, wxListItem& info, LV_ITEM& tvItem); | |
72 | static void wxConvertFromMSWListItem(const wxListCtrl *ctrl, wxListItem& info, LV_ITEM& tvItem, HWND getFullInfo = 0); | |
73 | ||
edccf428 | 74 | // ---------------------------------------------------------------------------- |
2e4df4bf | 75 | // events |
edccf428 VZ |
76 | // ---------------------------------------------------------------------------- |
77 | ||
2e4df4bf VZ |
78 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG) |
79 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG) | |
80 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT) | |
81 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT) | |
82 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM) | |
83 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS) | |
84 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO) | |
85 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO) | |
86 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED) | |
87 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED) | |
88 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN) | |
89 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM) | |
90 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK) | |
91 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK) | |
92 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK) | |
93 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED) | |
94 | ||
8f177c8e VZ |
95 | IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl) |
96 | IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject) | |
2bda0e17 | 97 | |
2702ed5a JS |
98 | BEGIN_EVENT_TABLE(wxListCtrl, wxControl) |
99 | EVT_PAINT(wxListCtrl::OnPaint) | |
100 | END_EVENT_TABLE() | |
101 | ||
edccf428 VZ |
102 | // ============================================================================ |
103 | // implementation | |
104 | // ============================================================================ | |
105 | ||
8f177c8e VZ |
106 | // ---------------------------------------------------------------------------- |
107 | // wxListEvent | |
108 | // ---------------------------------------------------------------------------- | |
109 | ||
110 | void wxListEvent::CopyObject(wxObject& object_dest) const | |
111 | { | |
112 | wxListEvent *obj = (wxListEvent *)&object_dest; | |
113 | ||
114 | wxNotifyEvent::CopyObject(object_dest); | |
115 | ||
116 | obj->m_code = m_code; | |
117 | obj->m_itemIndex = m_itemIndex; | |
118 | obj->m_oldItemIndex = m_oldItemIndex; | |
119 | obj->m_col = m_col; | |
120 | obj->m_cancelled = m_cancelled; | |
121 | obj->m_pointDrag = m_pointDrag; | |
122 | obj->m_item.m_mask = m_item.m_mask; | |
123 | obj->m_item.m_itemId = m_item.m_itemId; | |
124 | obj->m_item.m_col = m_item.m_col; | |
125 | obj->m_item.m_state = m_item.m_state; | |
126 | obj->m_item.m_stateMask = m_item.m_stateMask; | |
127 | obj->m_item.m_text = m_item.m_text; | |
128 | obj->m_item.m_image = m_item.m_image; | |
129 | obj->m_item.m_data = m_item.m_data; | |
130 | obj->m_item.m_format = m_item.m_format; | |
131 | obj->m_item.m_width = m_item.m_width; | |
132 | ||
133 | if ( m_item.HasAttributes() ) | |
134 | { | |
135 | obj->m_item.SetTextColour(m_item.GetTextColour()); | |
136 | obj->m_item.SetBackgroundColour(m_item.GetBackgroundColour()); | |
137 | obj->m_item.SetFont(m_item.GetFont()); | |
138 | } | |
139 | } | |
140 | ||
edccf428 VZ |
141 | // ---------------------------------------------------------------------------- |
142 | // wxListCtrl construction | |
143 | // ---------------------------------------------------------------------------- | |
144 | ||
bdc72a22 | 145 | void wxListCtrl::Init() |
2bda0e17 | 146 | { |
0b5efdc7 VZ |
147 | m_imageListNormal = NULL; |
148 | m_imageListSmall = NULL; | |
149 | m_imageListState = NULL; | |
2e12c11a | 150 | m_ownsImageListNormal = m_ownsImageListSmall = m_ownsImageListState = FALSE; |
0b5efdc7 | 151 | m_baseStyle = 0; |
2bda0e17 | 152 | m_colCount = 0; |
bbcdf8bc | 153 | m_textCtrl = NULL; |
bdc72a22 | 154 | m_hasAnyAttr = FALSE; |
2bda0e17 KB |
155 | } |
156 | ||
0b5efdc7 VZ |
157 | bool wxListCtrl::Create(wxWindow *parent, |
158 | wxWindowID id, | |
159 | const wxPoint& pos, | |
160 | const wxSize& size, | |
161 | long style, | |
162 | const wxValidator& validator, | |
163 | const wxString& name) | |
2bda0e17 | 164 | { |
11b6a93b | 165 | #if wxUSE_VALIDATORS |
0b5efdc7 | 166 | SetValidator(validator); |
11b6a93b VZ |
167 | #endif // wxUSE_VALIDATORS |
168 | ||
0b5efdc7 | 169 | SetName(name); |
2bda0e17 | 170 | |
0b5efdc7 VZ |
171 | int x = pos.x; |
172 | int y = pos.y; | |
173 | int width = size.x; | |
174 | int height = size.y; | |
2bda0e17 | 175 | |
0b5efdc7 | 176 | m_windowStyle = style; |
2bda0e17 | 177 | |
0b5efdc7 | 178 | SetParent(parent); |
2bda0e17 | 179 | |
0b5efdc7 VZ |
180 | if (width <= 0) |
181 | width = 100; | |
182 | if (height <= 0) | |
183 | height = 30; | |
184 | if (x < 0) | |
185 | x = 0; | |
186 | if (y < 0) | |
187 | y = 0; | |
2bda0e17 | 188 | |
0b5efdc7 | 189 | m_windowId = (id == -1) ? NewControlId() : id; |
2bda0e17 | 190 | |
edccf428 VZ |
191 | DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP | |
192 | LVS_SHAREIMAGELISTS | LVS_SHOWSELALWAYS; | |
193 | if ( wxStyleHasBorder(m_windowStyle) ) | |
194 | wstyle |= WS_BORDER; | |
195 | m_baseStyle = wstyle; | |
196 | ||
197 | if ( !DoCreateControl(x, y, width, height) ) | |
198 | return FALSE; | |
199 | ||
200 | if (parent) | |
201 | parent->AddChild(this); | |
202 | ||
203 | return TRUE; | |
204 | } | |
205 | ||
206 | bool wxListCtrl::DoCreateControl(int x, int y, int w, int h) | |
207 | { | |
208 | DWORD wstyle = m_baseStyle; | |
2bda0e17 | 209 | |
0b5efdc7 | 210 | bool want3D; |
edccf428 | 211 | WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D); |
2bda0e17 | 212 | |
0b5efdc7 VZ |
213 | // Even with extended styles, need to combine with WS_BORDER |
214 | // for them to look right. | |
edccf428 | 215 | if ( want3D ) |
0b5efdc7 | 216 | wstyle |= WS_BORDER; |
2bda0e17 | 217 | |
0b5efdc7 VZ |
218 | long oldStyle = 0; // Dummy |
219 | wstyle |= ConvertToMSWStyle(oldStyle, m_windowStyle); | |
2bda0e17 | 220 | |
0b5efdc7 VZ |
221 | // Create the ListView control. |
222 | m_hWnd = (WXHWND)CreateWindowEx(exStyle, | |
223 | WC_LISTVIEW, | |
223d09f6 | 224 | wxT(""), |
0b5efdc7 | 225 | wstyle, |
edccf428 VZ |
226 | x, y, w, h, |
227 | GetWinHwnd(GetParent()), | |
0b5efdc7 VZ |
228 | (HMENU)m_windowId, |
229 | wxGetInstance(), | |
230 | NULL); | |
f8352807 | 231 | |
edccf428 VZ |
232 | if ( !m_hWnd ) |
233 | { | |
f6bcfd97 | 234 | wxLogError(_("Can't create list control window, check that comctl32.dll is installed.")); |
0b5efdc7 VZ |
235 | |
236 | return FALSE; | |
237 | } | |
238 | ||
239 | // for comctl32.dll v 4.70+ we want to have this attribute because it's | |
240 | // prettier (and also because wxGTK does it like this) | |
225fe9d6 | 241 | if ( (wstyle & LVS_REPORT) && wxTheApp->GetComCtl32Version() >= 470 ) |
0b5efdc7 | 242 | { |
225fe9d6 VZ |
243 | ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE, |
244 | 0, LVS_EX_FULLROWSELECT); | |
0b5efdc7 | 245 | } |
f8352807 | 246 | |
5aeeab14 | 247 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW)); |
edccf428 | 248 | SetForegroundColour(GetParent()->GetForegroundColour()); |
2bda0e17 | 249 | |
edccf428 | 250 | SubclassWin(m_hWnd); |
2bda0e17 | 251 | |
0b5efdc7 | 252 | return TRUE; |
2bda0e17 KB |
253 | } |
254 | ||
edccf428 VZ |
255 | void wxListCtrl::UpdateStyle() |
256 | { | |
257 | if ( GetHWND() ) | |
258 | { | |
259 | // The new window view style | |
260 | long dummy; | |
261 | DWORD dwStyleNew = ConvertToMSWStyle(dummy, m_windowStyle); | |
262 | dwStyleNew |= m_baseStyle; | |
263 | ||
910484a6 | 264 | // Get the current window style. |
edccf428 VZ |
265 | DWORD dwStyleOld = ::GetWindowLong(GetHwnd(), GWL_STYLE); |
266 | ||
910484a6 | 267 | // Only set the window style if the view bits have changed. |
edccf428 VZ |
268 | if ( dwStyleOld != dwStyleNew ) |
269 | { | |
270 | ::SetWindowLong(GetHwnd(), GWL_STYLE, dwStyleNew); | |
271 | } | |
272 | } | |
273 | } | |
274 | ||
91b4c08d | 275 | void wxListCtrl::FreeAllAttrs(bool dontRecreate) |
2bda0e17 | 276 | { |
d62228a6 VZ |
277 | if ( m_hasAnyAttr ) |
278 | { | |
279 | for ( wxNode *node = m_attrs.Next(); node; node = m_attrs.Next() ) | |
280 | { | |
281 | delete (wxListItemAttr *)node->Data(); | |
282 | } | |
6932a32c VZ |
283 | |
284 | m_attrs.Destroy(); | |
91b4c08d VZ |
285 | if ( !dontRecreate ) |
286 | { | |
287 | m_attrs.Create(wxKEY_INTEGER, 1000); // just as def ctor | |
288 | } | |
6932a32c VZ |
289 | |
290 | m_hasAnyAttr = FALSE; | |
d62228a6 | 291 | } |
6932a32c | 292 | } |
d62228a6 | 293 | |
6932a32c VZ |
294 | wxListCtrl::~wxListCtrl() |
295 | { | |
91b4c08d VZ |
296 | FreeAllAttrs(TRUE /* no need to recreate hash any more */); |
297 | ||
d62228a6 | 298 | if ( m_textCtrl ) |
bbcdf8bc | 299 | { |
0b5efdc7 VZ |
300 | m_textCtrl->UnsubclassWin(); |
301 | m_textCtrl->SetHWND(0); | |
302 | delete m_textCtrl; | |
303 | m_textCtrl = NULL; | |
bbcdf8bc | 304 | } |
33ac7e6f | 305 | |
2e12c11a VS |
306 | if (m_ownsImageListNormal) delete m_imageListNormal; |
307 | if (m_ownsImageListSmall) delete m_imageListSmall; | |
308 | if (m_ownsImageListState) delete m_imageListState; | |
2bda0e17 KB |
309 | } |
310 | ||
edccf428 VZ |
311 | // ---------------------------------------------------------------------------- |
312 | // set/get/change style | |
313 | // ---------------------------------------------------------------------------- | |
314 | ||
2bda0e17 | 315 | // Add or remove a single window style |
debe6624 | 316 | void wxListCtrl::SetSingleStyle(long style, bool add) |
2bda0e17 | 317 | { |
0b5efdc7 | 318 | long flag = GetWindowStyleFlag(); |
2bda0e17 | 319 | |
0b5efdc7 | 320 | // Get rid of conflicting styles |
acb62b84 VZ |
321 | if ( add ) |
322 | { | |
0b5efdc7 | 323 | if ( style & wxLC_MASK_TYPE) |
edccf428 | 324 | flag = flag & ~wxLC_MASK_TYPE; |
0b5efdc7 | 325 | if ( style & wxLC_MASK_ALIGN ) |
edccf428 | 326 | flag = flag & ~wxLC_MASK_ALIGN; |
0b5efdc7 | 327 | if ( style & wxLC_MASK_SORT ) |
edccf428 | 328 | flag = flag & ~wxLC_MASK_SORT; |
acb62b84 | 329 | } |
2bda0e17 | 330 | |
0b5efdc7 VZ |
331 | if ( flag & style ) |
332 | { | |
333 | if ( !add ) | |
334 | flag -= style; | |
335 | } | |
336 | else | |
337 | { | |
338 | if ( add ) | |
339 | { | |
340 | flag |= style; | |
341 | } | |
342 | } | |
343 | ||
344 | m_windowStyle = flag; | |
2bda0e17 | 345 | |
edccf428 | 346 | UpdateStyle(); |
2bda0e17 KB |
347 | } |
348 | ||
349 | // Set the whole window style | |
debe6624 | 350 | void wxListCtrl::SetWindowStyleFlag(long flag) |
2bda0e17 | 351 | { |
0b5efdc7 | 352 | m_windowStyle = flag; |
2bda0e17 | 353 | |
edccf428 | 354 | UpdateStyle(); |
2bda0e17 KB |
355 | } |
356 | ||
0b5efdc7 VZ |
357 | // Can be just a single style, or a bitlist |
358 | long wxListCtrl::ConvertToMSWStyle(long& oldStyle, long style) const | |
2bda0e17 | 359 | { |
0b5efdc7 VZ |
360 | long wstyle = 0; |
361 | if ( style & wxLC_ICON ) | |
362 | { | |
363 | if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON ) | |
364 | oldStyle -= LVS_SMALLICON; | |
365 | if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT ) | |
366 | oldStyle -= LVS_REPORT; | |
367 | if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST ) | |
368 | oldStyle -= LVS_LIST; | |
369 | wstyle |= LVS_ICON; | |
370 | } | |
371 | ||
372 | if ( style & wxLC_SMALL_ICON ) | |
373 | { | |
374 | if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON ) | |
375 | oldStyle -= LVS_ICON; | |
376 | if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT ) | |
377 | oldStyle -= LVS_REPORT; | |
378 | if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST ) | |
379 | oldStyle -= LVS_LIST; | |
380 | wstyle |= LVS_SMALLICON; | |
381 | } | |
382 | ||
383 | if ( style & wxLC_LIST ) | |
384 | { | |
385 | if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON ) | |
386 | oldStyle -= LVS_ICON; | |
387 | if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT ) | |
388 | oldStyle -= LVS_REPORT; | |
389 | if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON ) | |
390 | oldStyle -= LVS_SMALLICON; | |
391 | wstyle |= LVS_LIST; | |
392 | } | |
2bda0e17 | 393 | |
0b5efdc7 VZ |
394 | if ( style & wxLC_REPORT ) |
395 | { | |
396 | if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON ) | |
397 | oldStyle -= LVS_ICON; | |
398 | if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST ) | |
399 | oldStyle -= LVS_LIST; | |
400 | if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON ) | |
401 | oldStyle -= LVS_SMALLICON; | |
402 | ||
403 | wstyle |= LVS_REPORT; | |
404 | } | |
2bda0e17 | 405 | |
0b5efdc7 VZ |
406 | if ( style & wxLC_ALIGN_LEFT ) |
407 | { | |
408 | if ( oldStyle & LVS_ALIGNTOP ) | |
409 | oldStyle -= LVS_ALIGNTOP; | |
410 | wstyle |= LVS_ALIGNLEFT; | |
411 | } | |
2bda0e17 | 412 | |
0b5efdc7 VZ |
413 | if ( style & wxLC_ALIGN_TOP ) |
414 | { | |
415 | if ( oldStyle & LVS_ALIGNLEFT ) | |
416 | oldStyle -= LVS_ALIGNLEFT; | |
417 | wstyle |= LVS_ALIGNTOP; | |
418 | } | |
2bda0e17 | 419 | |
0b5efdc7 VZ |
420 | if ( style & wxLC_AUTOARRANGE ) |
421 | wstyle |= LVS_AUTOARRANGE; | |
2bda0e17 | 422 | |
0b5efdc7 VZ |
423 | // Apparently, no such style (documentation wrong?) |
424 | /* | |
425 | if ( style & wxLC_BUTTON ) | |
426 | wstyle |= LVS_BUTTON; | |
427 | */ | |
2bda0e17 | 428 | |
0b5efdc7 VZ |
429 | if ( style & wxLC_NO_SORT_HEADER ) |
430 | wstyle |= LVS_NOSORTHEADER; | |
2bda0e17 | 431 | |
0b5efdc7 VZ |
432 | if ( style & wxLC_NO_HEADER ) |
433 | wstyle |= LVS_NOCOLUMNHEADER; | |
434 | ||
435 | if ( style & wxLC_EDIT_LABELS ) | |
436 | wstyle |= LVS_EDITLABELS; | |
437 | ||
438 | if ( style & wxLC_SINGLE_SEL ) | |
439 | wstyle |= LVS_SINGLESEL; | |
440 | ||
441 | if ( style & wxLC_SORT_ASCENDING ) | |
442 | { | |
443 | if ( oldStyle & LVS_SORTDESCENDING ) | |
444 | oldStyle -= LVS_SORTDESCENDING; | |
445 | wstyle |= LVS_SORTASCENDING; | |
446 | } | |
447 | ||
448 | if ( style & wxLC_SORT_DESCENDING ) | |
449 | { | |
450 | if ( oldStyle & LVS_SORTASCENDING ) | |
451 | oldStyle -= LVS_SORTASCENDING; | |
452 | wstyle |= LVS_SORTDESCENDING; | |
453 | } | |
454 | ||
455 | return wstyle; | |
2bda0e17 KB |
456 | } |
457 | ||
edccf428 VZ |
458 | // ---------------------------------------------------------------------------- |
459 | // accessors | |
460 | // ---------------------------------------------------------------------------- | |
461 | ||
91b4c08d VZ |
462 | // Sets the foreground, i.e. text, colour |
463 | bool wxListCtrl::SetForegroundColour(const wxColour& col) | |
464 | { | |
465 | if ( !wxWindow::SetForegroundColour(col) ) | |
466 | return FALSE; | |
467 | ||
468 | ListView_SetTextColor(GetHwnd(), wxColourToRGB(col)); | |
469 | ||
470 | return TRUE; | |
471 | } | |
472 | ||
473 | // Sets the background colour | |
cc2b7472 | 474 | bool wxListCtrl::SetBackgroundColour(const wxColour& col) |
2bda0e17 | 475 | { |
cc2b7472 VZ |
476 | if ( !wxWindow::SetBackgroundColour(col) ) |
477 | return FALSE; | |
2bda0e17 | 478 | |
91b4c08d VZ |
479 | // we set the same colour for both the "empty" background and the items |
480 | // background | |
481 | COLORREF color = wxColourToRGB(col); | |
482 | ListView_SetBkColor(GetHwnd(), color); | |
483 | ListView_SetTextBkColor(GetHwnd(), color); | |
cc2b7472 VZ |
484 | |
485 | return TRUE; | |
2bda0e17 KB |
486 | } |
487 | ||
488 | // Gets information about this column | |
debe6624 | 489 | bool wxListCtrl::GetColumn(int col, wxListItem& item) const |
2bda0e17 | 490 | { |
0b5efdc7 VZ |
491 | LV_COLUMN lvCol; |
492 | lvCol.mask = 0; | |
493 | lvCol.fmt = 0; | |
494 | lvCol.pszText = NULL; | |
495 | ||
496 | if ( item.m_mask & wxLIST_MASK_TEXT ) | |
497 | { | |
498 | lvCol.mask |= LVCF_TEXT; | |
837e5743 | 499 | lvCol.pszText = new wxChar[513]; |
0b5efdc7 VZ |
500 | lvCol.cchTextMax = 512; |
501 | } | |
502 | ||
edccf428 | 503 | bool success = (ListView_GetColumn(GetHwnd(), col, & lvCol) != 0); |
0b5efdc7 VZ |
504 | |
505 | // item.m_subItem = lvCol.iSubItem; | |
506 | item.m_width = lvCol.cx; | |
507 | ||
508 | if ( (item.m_mask & wxLIST_MASK_TEXT) && lvCol.pszText ) | |
509 | { | |
510 | item.m_text = lvCol.pszText; | |
511 | delete[] lvCol.pszText; | |
512 | } | |
513 | ||
514 | if ( item.m_mask & wxLIST_MASK_FORMAT ) | |
515 | { | |
516 | if (lvCol.fmt == LVCFMT_LEFT) | |
517 | item.m_format = wxLIST_FORMAT_LEFT; | |
518 | else if (lvCol.fmt == LVCFMT_RIGHT) | |
519 | item.m_format = wxLIST_FORMAT_RIGHT; | |
520 | else if (lvCol.fmt == LVCFMT_CENTER) | |
521 | item.m_format = wxLIST_FORMAT_CENTRE; | |
2bda0e17 KB |
522 | } |
523 | ||
0b5efdc7 | 524 | return success; |
2bda0e17 KB |
525 | } |
526 | ||
527 | // Sets information about this column | |
debe6624 | 528 | bool wxListCtrl::SetColumn(int col, wxListItem& item) |
2bda0e17 | 529 | { |
0b5efdc7 VZ |
530 | LV_COLUMN lvCol; |
531 | lvCol.mask = 0; | |
532 | lvCol.fmt = 0; | |
533 | lvCol.pszText = NULL; | |
534 | ||
535 | if ( item.m_mask & wxLIST_MASK_TEXT ) | |
536 | { | |
537 | lvCol.mask |= LVCF_TEXT; | |
538 | lvCol.pszText = WXSTRINGCAST item.m_text; | |
539 | lvCol.cchTextMax = 0; // Ignored | |
540 | } | |
541 | if ( item.m_mask & wxLIST_MASK_FORMAT ) | |
542 | { | |
543 | lvCol.mask |= LVCF_FMT; | |
544 | ||
545 | if ( item.m_format == wxLIST_FORMAT_LEFT ) | |
546 | lvCol.fmt = LVCFMT_LEFT; | |
547 | if ( item.m_format == wxLIST_FORMAT_RIGHT ) | |
548 | lvCol.fmt = LVCFMT_RIGHT; | |
549 | if ( item.m_format == wxLIST_FORMAT_CENTRE ) | |
550 | lvCol.fmt = LVCFMT_CENTER; | |
2bda0e17 KB |
551 | } |
552 | ||
0b5efdc7 VZ |
553 | if ( item.m_mask & wxLIST_MASK_WIDTH ) |
554 | { | |
555 | lvCol.mask |= LVCF_WIDTH; | |
556 | lvCol.cx = item.m_width; | |
2bda0e17 | 557 | |
0b5efdc7 VZ |
558 | if ( lvCol.cx == wxLIST_AUTOSIZE) |
559 | lvCol.cx = LVSCW_AUTOSIZE; | |
560 | else if ( lvCol.cx == wxLIST_AUTOSIZE_USEHEADER) | |
561 | lvCol.cx = LVSCW_AUTOSIZE_USEHEADER; | |
562 | } | |
563 | lvCol.mask |= LVCF_SUBITEM; | |
564 | lvCol.iSubItem = col; | |
edccf428 | 565 | return (ListView_SetColumn(GetHwnd(), col, & lvCol) != 0); |
2bda0e17 KB |
566 | } |
567 | ||
568 | // Gets the column width | |
debe6624 | 569 | int wxListCtrl::GetColumnWidth(int col) const |
2bda0e17 | 570 | { |
edccf428 | 571 | return ListView_GetColumnWidth(GetHwnd(), col); |
2bda0e17 KB |
572 | } |
573 | ||
574 | // Sets the column width | |
debe6624 | 575 | bool wxListCtrl::SetColumnWidth(int col, int width) |
2bda0e17 | 576 | { |
0b5efdc7 VZ |
577 | int col2 = col; |
578 | if ( m_windowStyle & wxLC_LIST ) | |
579 | col2 = -1; | |
2bda0e17 | 580 | |
0b5efdc7 VZ |
581 | int width2 = width; |
582 | if ( width2 == wxLIST_AUTOSIZE) | |
583 | width2 = LVSCW_AUTOSIZE; | |
584 | else if ( width2 == wxLIST_AUTOSIZE_USEHEADER) | |
585 | width2 = LVSCW_AUTOSIZE_USEHEADER; | |
2bda0e17 | 586 | |
edccf428 | 587 | return (ListView_SetColumnWidth(GetHwnd(), col2, width2) != 0); |
2bda0e17 KB |
588 | } |
589 | ||
590 | // Gets the number of items that can fit vertically in the | |
591 | // visible area of the list control (list or report view) | |
592 | // or the total number of items in the list control (icon | |
593 | // or small icon view) | |
c42404a5 | 594 | int wxListCtrl::GetCountPerPage() const |
2bda0e17 | 595 | { |
edccf428 | 596 | return ListView_GetCountPerPage(GetHwnd()); |
2bda0e17 KB |
597 | } |
598 | ||
599 | // Gets the edit control for editing labels. | |
c42404a5 | 600 | wxTextCtrl* wxListCtrl::GetEditControl() const |
2bda0e17 | 601 | { |
bbcdf8bc | 602 | return m_textCtrl; |
2bda0e17 KB |
603 | } |
604 | ||
605 | // Gets information about the item | |
606 | bool wxListCtrl::GetItem(wxListItem& info) const | |
607 | { | |
0b5efdc7 | 608 | LV_ITEM lvItem; |
11c7d5b6 | 609 | wxZeroMemory(lvItem); |
2bda0e17 | 610 | |
0b5efdc7 | 611 | lvItem.iItem = info.m_itemId; |
fc5a93cd | 612 | lvItem.iSubItem = info.m_col; |
0b5efdc7 VZ |
613 | |
614 | if ( info.m_mask & wxLIST_MASK_TEXT ) | |
615 | { | |
616 | lvItem.mask |= LVIF_TEXT; | |
837e5743 | 617 | lvItem.pszText = new wxChar[513]; |
0b5efdc7 VZ |
618 | lvItem.cchTextMax = 512; |
619 | } | |
620 | else | |
621 | { | |
622 | lvItem.pszText = NULL; | |
623 | } | |
624 | ||
625 | if (info.m_mask & wxLIST_MASK_DATA) | |
edccf428 | 626 | lvItem.mask |= LVIF_PARAM; |
0b5efdc7 | 627 | |
2189c644 JS |
628 | if (info.m_mask & wxLIST_MASK_IMAGE) |
629 | lvItem.mask |= LVIF_IMAGE; | |
630 | ||
0b5efdc7 VZ |
631 | if ( info.m_mask & wxLIST_MASK_STATE ) |
632 | { | |
633 | lvItem.mask |= LVIF_STATE; | |
634 | // the other bits are hardly interesting anyhow | |
635 | lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED; | |
636 | } | |
637 | ||
638 | bool success = ListView_GetItem((HWND)GetHWND(), &lvItem) != 0; | |
639 | if ( !success ) | |
640 | { | |
641 | wxLogError(_("Couldn't retrieve information about list control item %d."), | |
642 | lvItem.iItem); | |
643 | } | |
644 | else | |
645 | { | |
646 | wxConvertFromMSWListItem(this, info, lvItem); | |
647 | } | |
648 | ||
649 | if (lvItem.pszText) | |
650 | delete[] lvItem.pszText; | |
651 | ||
652 | return success; | |
2bda0e17 KB |
653 | } |
654 | ||
655 | // Sets information about the item | |
656 | bool wxListCtrl::SetItem(wxListItem& info) | |
657 | { | |
0b5efdc7 | 658 | LV_ITEM item; |
2bda0e17 | 659 | wxConvertToMSWListItem(this, info, item); |
bdc72a22 VZ |
660 | |
661 | // check whether it has any custom attributes | |
662 | if ( info.HasAttributes() ) | |
663 | { | |
2702ed5a | 664 | |
35ec54d3 VS |
665 | wxListItemAttr *attr; |
666 | attr = (wxListItemAttr*) m_attrs.Get(item.iItem); | |
2702ed5a | 667 | |
35ec54d3 | 668 | if (attr == NULL) |
2702ed5a | 669 | |
35ec54d3 | 670 | m_attrs.Put(item.iItem, (wxObject *)new wxListItemAttr(*info.GetAttributes())); |
2702ed5a | 671 | |
35ec54d3 | 672 | else *attr = *info.GetAttributes(); |
bdc72a22 VZ |
673 | |
674 | m_hasAnyAttr = TRUE; | |
675 | } | |
bdc72a22 | 676 | |
0b5efdc7 | 677 | item.cchTextMax = 0; |
7cc98b3e VZ |
678 | bool ok = ListView_SetItem(GetHwnd(), &item) != 0; |
679 | if ( ok && (info.m_mask & wxLIST_MASK_IMAGE) ) | |
680 | { | |
681 | // make the change visible | |
682 | ListView_Update(GetHwnd(), item.iItem); | |
683 | } | |
684 | ||
685 | return ok; | |
2bda0e17 KB |
686 | } |
687 | ||
debe6624 | 688 | long wxListCtrl::SetItem(long index, int col, const wxString& label, int imageId) |
2bda0e17 | 689 | { |
0b5efdc7 VZ |
690 | wxListItem info; |
691 | info.m_text = label; | |
692 | info.m_mask = wxLIST_MASK_TEXT; | |
693 | info.m_itemId = index; | |
694 | info.m_col = col; | |
695 | if ( imageId > -1 ) | |
696 | { | |
697 | info.m_image = imageId; | |
698 | info.m_mask |= wxLIST_MASK_IMAGE; | |
699 | } | |
700 | return SetItem(info); | |
2bda0e17 KB |
701 | } |
702 | ||
703 | ||
704 | // Gets the item state | |
debe6624 | 705 | int wxListCtrl::GetItemState(long item, long stateMask) const |
2bda0e17 | 706 | { |
0b5efdc7 | 707 | wxListItem info; |
2bda0e17 | 708 | |
edccf428 | 709 | info.m_mask = wxLIST_MASK_STATE; |
0b5efdc7 VZ |
710 | info.m_stateMask = stateMask; |
711 | info.m_itemId = item; | |
2bda0e17 | 712 | |
0b5efdc7 VZ |
713 | if (!GetItem(info)) |
714 | return 0; | |
2bda0e17 | 715 | |
0b5efdc7 | 716 | return info.m_state; |
2bda0e17 KB |
717 | } |
718 | ||
719 | // Sets the item state | |
debe6624 | 720 | bool wxListCtrl::SetItemState(long item, long state, long stateMask) |
2bda0e17 | 721 | { |
0b5efdc7 | 722 | wxListItem info; |
2bda0e17 | 723 | |
edccf428 | 724 | info.m_mask = wxLIST_MASK_STATE; |
0b5efdc7 VZ |
725 | info.m_state = state; |
726 | info.m_stateMask = stateMask; | |
727 | info.m_itemId = item; | |
2bda0e17 | 728 | |
0b5efdc7 | 729 | return SetItem(info); |
2bda0e17 KB |
730 | } |
731 | ||
732 | // Sets the item image | |
33ac7e6f | 733 | bool wxListCtrl::SetItemImage(long item, int image, int WXUNUSED(selImage)) |
2bda0e17 | 734 | { |
0b5efdc7 | 735 | wxListItem info; |
2bda0e17 | 736 | |
edccf428 | 737 | info.m_mask = wxLIST_MASK_IMAGE; |
0b5efdc7 VZ |
738 | info.m_image = image; |
739 | info.m_itemId = item; | |
2bda0e17 | 740 | |
0b5efdc7 | 741 | return SetItem(info); |
2bda0e17 KB |
742 | } |
743 | ||
744 | // Gets the item text | |
debe6624 | 745 | wxString wxListCtrl::GetItemText(long item) const |
2bda0e17 | 746 | { |
0b5efdc7 | 747 | wxListItem info; |
2bda0e17 | 748 | |
edccf428 | 749 | info.m_mask = wxLIST_MASK_TEXT; |
0b5efdc7 | 750 | info.m_itemId = item; |
2bda0e17 | 751 | |
0b5efdc7 VZ |
752 | if (!GetItem(info)) |
753 | return wxString(""); | |
754 | return info.m_text; | |
2bda0e17 KB |
755 | } |
756 | ||
757 | // Sets the item text | |
debe6624 | 758 | void wxListCtrl::SetItemText(long item, const wxString& str) |
2bda0e17 | 759 | { |
0b5efdc7 | 760 | wxListItem info; |
2bda0e17 | 761 | |
edccf428 | 762 | info.m_mask = wxLIST_MASK_TEXT; |
0b5efdc7 VZ |
763 | info.m_itemId = item; |
764 | info.m_text = str; | |
2bda0e17 | 765 | |
0b5efdc7 | 766 | SetItem(info); |
2bda0e17 KB |
767 | } |
768 | ||
769 | // Gets the item data | |
debe6624 | 770 | long wxListCtrl::GetItemData(long item) const |
2bda0e17 | 771 | { |
0b5efdc7 | 772 | wxListItem info; |
2bda0e17 | 773 | |
edccf428 | 774 | info.m_mask = wxLIST_MASK_DATA; |
0b5efdc7 | 775 | info.m_itemId = item; |
2bda0e17 | 776 | |
0b5efdc7 VZ |
777 | if (!GetItem(info)) |
778 | return 0; | |
779 | return info.m_data; | |
2bda0e17 KB |
780 | } |
781 | ||
782 | // Sets the item data | |
debe6624 | 783 | bool wxListCtrl::SetItemData(long item, long data) |
2bda0e17 | 784 | { |
0b5efdc7 | 785 | wxListItem info; |
2bda0e17 | 786 | |
edccf428 | 787 | info.m_mask = wxLIST_MASK_DATA; |
0b5efdc7 VZ |
788 | info.m_itemId = item; |
789 | info.m_data = data; | |
2bda0e17 | 790 | |
0b5efdc7 | 791 | return SetItem(info); |
2bda0e17 KB |
792 | } |
793 | ||
794 | // Gets the item rectangle | |
16e93305 | 795 | bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const |
2bda0e17 | 796 | { |
0b5efdc7 | 797 | RECT rect2; |
2bda0e17 | 798 | |
0b5efdc7 VZ |
799 | int code2 = LVIR_BOUNDS; |
800 | if ( code == wxLIST_RECT_BOUNDS ) | |
801 | code2 = LVIR_BOUNDS; | |
802 | else if ( code == wxLIST_RECT_ICON ) | |
803 | code2 = LVIR_ICON; | |
804 | else if ( code == wxLIST_RECT_LABEL ) | |
805 | code2 = LVIR_LABEL; | |
2bda0e17 | 806 | |
5ea105e0 | 807 | #ifdef __WXWINE__ |
edccf428 | 808 | bool success = (ListView_GetItemRect(GetHwnd(), (int) item, &rect2 ) != 0); |
5ea105e0 | 809 | #else |
edccf428 | 810 | bool success = (ListView_GetItemRect(GetHwnd(), (int) item, &rect2, code2) != 0); |
5ea105e0 | 811 | #endif |
2bda0e17 | 812 | |
0b5efdc7 VZ |
813 | rect.x = rect2.left; |
814 | rect.y = rect2.top; | |
815 | rect.width = rect2.right - rect2.left; | |
64acfbb2 | 816 | rect.height = rect2.bottom - rect2.top; |
0b5efdc7 | 817 | return success; |
2bda0e17 KB |
818 | } |
819 | ||
820 | // Gets the item position | |
debe6624 | 821 | bool wxListCtrl::GetItemPosition(long item, wxPoint& pos) const |
2bda0e17 | 822 | { |
0b5efdc7 | 823 | POINT pt; |
2bda0e17 | 824 | |
edccf428 | 825 | bool success = (ListView_GetItemPosition(GetHwnd(), (int) item, &pt) != 0); |
2bda0e17 | 826 | |
0b5efdc7 VZ |
827 | pos.x = pt.x; pos.y = pt.y; |
828 | return success; | |
2bda0e17 KB |
829 | } |
830 | ||
831 | // Sets the item position. | |
debe6624 | 832 | bool wxListCtrl::SetItemPosition(long item, const wxPoint& pos) |
2bda0e17 | 833 | { |
edccf428 | 834 | return (ListView_SetItemPosition(GetHwnd(), (int) item, pos.x, pos.y) != 0); |
2bda0e17 KB |
835 | } |
836 | ||
837 | // Gets the number of items in the list control | |
c42404a5 | 838 | int wxListCtrl::GetItemCount() const |
2bda0e17 | 839 | { |
edccf428 | 840 | return ListView_GetItemCount(GetHwnd()); |
2bda0e17 KB |
841 | } |
842 | ||
843 | // Retrieves the spacing between icons in pixels. | |
844 | // If small is TRUE, gets the spacing for the small icon | |
845 | // view, otherwise the large icon view. | |
846 | int wxListCtrl::GetItemSpacing(bool isSmall) const | |
847 | { | |
edccf428 | 848 | return ListView_GetItemSpacing(GetHwnd(), (BOOL) isSmall); |
2bda0e17 KB |
849 | } |
850 | ||
851 | // Gets the number of selected items in the list control | |
c42404a5 | 852 | int wxListCtrl::GetSelectedItemCount() const |
2bda0e17 | 853 | { |
edccf428 | 854 | return ListView_GetSelectedCount(GetHwnd()); |
2bda0e17 KB |
855 | } |
856 | ||
857 | // Gets the text colour of the listview | |
c42404a5 | 858 | wxColour wxListCtrl::GetTextColour() const |
2bda0e17 | 859 | { |
edccf428 | 860 | COLORREF ref = ListView_GetTextColor(GetHwnd()); |
0b5efdc7 VZ |
861 | wxColour col(GetRValue(ref), GetGValue(ref), GetBValue(ref)); |
862 | return col; | |
2bda0e17 KB |
863 | } |
864 | ||
865 | // Sets the text colour of the listview | |
866 | void wxListCtrl::SetTextColour(const wxColour& col) | |
867 | { | |
910484a6 | 868 | ListView_SetTextColor(GetHwnd(), PALETTERGB(col.Red(), col.Green(), col.Blue())); |
2bda0e17 KB |
869 | } |
870 | ||
871 | // Gets the index of the topmost visible item when in | |
872 | // list or report view | |
c42404a5 | 873 | long wxListCtrl::GetTopItem() const |
2bda0e17 | 874 | { |
edccf428 | 875 | return (long) ListView_GetTopIndex(GetHwnd()); |
2bda0e17 KB |
876 | } |
877 | ||
878 | // Searches for an item, starting from 'item'. | |
879 | // 'geometry' is one of | |
880 | // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT. | |
881 | // 'state' is a state bit flag, one or more of | |
882 | // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT. | |
883 | // item can be -1 to find the first item that matches the | |
884 | // specified flags. | |
885 | // Returns the item or -1 if unsuccessful. | |
debe6624 | 886 | long wxListCtrl::GetNextItem(long item, int geom, int state) const |
2bda0e17 | 887 | { |
0b5efdc7 | 888 | long flags = 0; |
2bda0e17 | 889 | |
0b5efdc7 VZ |
890 | if ( geom == wxLIST_NEXT_ABOVE ) |
891 | flags |= LVNI_ABOVE; | |
892 | if ( geom == wxLIST_NEXT_ALL ) | |
893 | flags |= LVNI_ALL; | |
894 | if ( geom == wxLIST_NEXT_BELOW ) | |
895 | flags |= LVNI_BELOW; | |
896 | if ( geom == wxLIST_NEXT_LEFT ) | |
897 | flags |= LVNI_TOLEFT; | |
898 | if ( geom == wxLIST_NEXT_RIGHT ) | |
899 | flags |= LVNI_TORIGHT; | |
2bda0e17 | 900 | |
0b5efdc7 VZ |
901 | if ( state & wxLIST_STATE_CUT ) |
902 | flags |= LVNI_CUT; | |
903 | if ( state & wxLIST_STATE_DROPHILITED ) | |
904 | flags |= LVNI_DROPHILITED; | |
905 | if ( state & wxLIST_STATE_FOCUSED ) | |
906 | flags |= LVNI_FOCUSED; | |
907 | if ( state & wxLIST_STATE_SELECTED ) | |
908 | flags |= LVNI_SELECTED; | |
2bda0e17 | 909 | |
edccf428 | 910 | return (long) ListView_GetNextItem(GetHwnd(), item, flags); |
2bda0e17 KB |
911 | } |
912 | ||
913 | ||
debe6624 | 914 | wxImageList *wxListCtrl::GetImageList(int which) const |
2bda0e17 | 915 | { |
0b5efdc7 | 916 | if ( which == wxIMAGE_LIST_NORMAL ) |
2bda0e17 | 917 | { |
0b5efdc7 VZ |
918 | return m_imageListNormal; |
919 | } | |
920 | else if ( which == wxIMAGE_LIST_SMALL ) | |
2bda0e17 | 921 | { |
0b5efdc7 VZ |
922 | return m_imageListSmall; |
923 | } | |
924 | else if ( which == wxIMAGE_LIST_STATE ) | |
2bda0e17 | 925 | { |
0b5efdc7 VZ |
926 | return m_imageListState; |
927 | } | |
928 | return NULL; | |
2bda0e17 KB |
929 | } |
930 | ||
debe6624 | 931 | void wxListCtrl::SetImageList(wxImageList *imageList, int which) |
2bda0e17 | 932 | { |
0b5efdc7 VZ |
933 | int flags = 0; |
934 | if ( which == wxIMAGE_LIST_NORMAL ) | |
2bda0e17 | 935 | { |
0b5efdc7 | 936 | flags = LVSIL_NORMAL; |
2e12c11a | 937 | if (m_ownsImageListNormal) delete m_imageListNormal; |
0b5efdc7 | 938 | m_imageListNormal = imageList; |
2e12c11a | 939 | m_ownsImageListNormal = FALSE; |
0b5efdc7 VZ |
940 | } |
941 | else if ( which == wxIMAGE_LIST_SMALL ) | |
2bda0e17 | 942 | { |
0b5efdc7 | 943 | flags = LVSIL_SMALL; |
2e12c11a | 944 | if (m_ownsImageListSmall) delete m_imageListSmall; |
0b5efdc7 | 945 | m_imageListSmall = imageList; |
2e12c11a | 946 | m_ownsImageListSmall = FALSE; |
0b5efdc7 VZ |
947 | } |
948 | else if ( which == wxIMAGE_LIST_STATE ) | |
2bda0e17 | 949 | { |
0b5efdc7 | 950 | flags = LVSIL_STATE; |
2e12c11a | 951 | if (m_ownsImageListState) delete m_imageListState; |
0b5efdc7 | 952 | m_imageListState = imageList; |
2e12c11a | 953 | m_ownsImageListState = FALSE; |
0b5efdc7 | 954 | } |
edccf428 | 955 | ListView_SetImageList(GetHwnd(), (HIMAGELIST) imageList ? imageList->GetHIMAGELIST() : 0, flags); |
2bda0e17 KB |
956 | } |
957 | ||
2e12c11a VS |
958 | void wxListCtrl::AssignImageList(wxImageList *imageList, int which) |
959 | { | |
960 | SetImageList(imageList, which); | |
961 | if ( which == wxIMAGE_LIST_NORMAL ) | |
962 | m_ownsImageListNormal = TRUE; | |
963 | else if ( which == wxIMAGE_LIST_SMALL ) | |
964 | m_ownsImageListSmall = TRUE; | |
965 | else if ( which == wxIMAGE_LIST_STATE ) | |
966 | m_ownsImageListState = TRUE; | |
967 | } | |
968 | ||
edccf428 | 969 | // ---------------------------------------------------------------------------- |
2bda0e17 | 970 | // Operations |
edccf428 | 971 | // ---------------------------------------------------------------------------- |
2bda0e17 KB |
972 | |
973 | // Arranges the items | |
debe6624 | 974 | bool wxListCtrl::Arrange(int flag) |
2bda0e17 | 975 | { |
0b5efdc7 VZ |
976 | UINT code = 0; |
977 | if ( flag == wxLIST_ALIGN_LEFT ) | |
978 | code = LVA_ALIGNLEFT; | |
979 | else if ( flag == wxLIST_ALIGN_TOP ) | |
980 | code = LVA_ALIGNTOP; | |
981 | else if ( flag == wxLIST_ALIGN_DEFAULT ) | |
982 | code = LVA_DEFAULT; | |
983 | else if ( flag == wxLIST_ALIGN_SNAP_TO_GRID ) | |
984 | code = LVA_SNAPTOGRID; | |
2bda0e17 | 985 | |
edccf428 | 986 | return (ListView_Arrange(GetHwnd(), code) != 0); |
2bda0e17 KB |
987 | } |
988 | ||
989 | // Deletes an item | |
debe6624 | 990 | bool wxListCtrl::DeleteItem(long item) |
2bda0e17 | 991 | { |
edccf428 | 992 | return (ListView_DeleteItem(GetHwnd(), (int) item) != 0); |
2bda0e17 KB |
993 | } |
994 | ||
995 | // Deletes all items | |
0b5efdc7 | 996 | bool wxListCtrl::DeleteAllItems() |
2bda0e17 | 997 | { |
edccf428 | 998 | return (ListView_DeleteAllItems(GetHwnd()) != 0); |
2bda0e17 KB |
999 | } |
1000 | ||
1001 | // Deletes all items | |
0b5efdc7 | 1002 | bool wxListCtrl::DeleteAllColumns() |
2bda0e17 | 1003 | { |
edccf428 | 1004 | while ( m_colCount > 0 ) |
2bda0e17 | 1005 | { |
edccf428 VZ |
1006 | if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 ) |
1007 | { | |
f6bcfd97 | 1008 | wxLogLastError(wxT("ListView_DeleteColumn")); |
edccf428 VZ |
1009 | |
1010 | return FALSE; | |
1011 | } | |
1012 | ||
1013 | m_colCount--; | |
2bda0e17 | 1014 | } |
edccf428 | 1015 | |
223d09f6 | 1016 | wxASSERT_MSG( m_colCount == 0, wxT("no columns should be left") ); |
edccf428 VZ |
1017 | |
1018 | return TRUE; | |
2bda0e17 KB |
1019 | } |
1020 | ||
1021 | // Deletes a column | |
debe6624 | 1022 | bool wxListCtrl::DeleteColumn(int col) |
2bda0e17 | 1023 | { |
edccf428 | 1024 | bool success = (ListView_DeleteColumn(GetHwnd(), col) != 0); |
2bda0e17 KB |
1025 | |
1026 | if ( success && (m_colCount > 0) ) | |
1027 | m_colCount --; | |
1028 | return success; | |
1029 | } | |
1030 | ||
1031 | // Clears items, and columns if there are any. | |
0b5efdc7 | 1032 | void wxListCtrl::ClearAll() |
2bda0e17 KB |
1033 | { |
1034 | DeleteAllItems(); | |
1035 | if ( m_colCount > 0 ) | |
1036 | DeleteAllColumns(); | |
1037 | } | |
1038 | ||
bbcdf8bc JS |
1039 | wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass) |
1040 | { | |
1041 | wxASSERT( (textControlClass->IsKindOf(CLASSINFO(wxTextCtrl))) ); | |
1042 | ||
edccf428 | 1043 | HWND hWnd = (HWND) ListView_EditLabel(GetHwnd(), item); |
bbcdf8bc JS |
1044 | |
1045 | if (m_textCtrl) | |
1046 | { | |
0b5efdc7 VZ |
1047 | m_textCtrl->UnsubclassWin(); |
1048 | m_textCtrl->SetHWND(0); | |
1049 | delete m_textCtrl; | |
1050 | m_textCtrl = NULL; | |
bbcdf8bc JS |
1051 | } |
1052 | ||
1053 | m_textCtrl = (wxTextCtrl*) textControlClass->CreateObject(); | |
1054 | m_textCtrl->SetHWND((WXHWND) hWnd); | |
1055 | m_textCtrl->SubclassWin((WXHWND) hWnd); | |
1056 | ||
1057 | return m_textCtrl; | |
1058 | } | |
1059 | ||
1060 | // End label editing, optionally cancelling the edit | |
33ac7e6f | 1061 | bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel)) |
2bda0e17 | 1062 | { |
341287bf | 1063 | wxFAIL; |
bbcdf8bc | 1064 | |
0b5efdc7 VZ |
1065 | /* I don't know how to implement this: there's no such macro as ListView_EndEditLabelNow. |
1066 | * ??? | |
edccf428 | 1067 | bool success = (ListView_EndEditLabelNow(GetHwnd(), cancel) != 0); |
0b5efdc7 VZ |
1068 | |
1069 | if (m_textCtrl) | |
1070 | { | |
1071 | m_textCtrl->UnsubclassWin(); | |
1072 | m_textCtrl->SetHWND(0); | |
1073 | delete m_textCtrl; | |
1074 | m_textCtrl = NULL; | |
1075 | } | |
1076 | return success; | |
1077 | */ | |
1078 | return FALSE; | |
2bda0e17 KB |
1079 | } |
1080 | ||
bbcdf8bc | 1081 | |
2bda0e17 | 1082 | // Ensures this item is visible |
debe6624 | 1083 | bool wxListCtrl::EnsureVisible(long item) |
2bda0e17 | 1084 | { |
edccf428 | 1085 | return (ListView_EnsureVisible(GetHwnd(), (int) item, FALSE) != 0); |
2bda0e17 KB |
1086 | } |
1087 | ||
1088 | // Find an item whose label matches this string, starting from the item after 'start' | |
1089 | // or the beginning if 'start' is -1. | |
debe6624 | 1090 | long wxListCtrl::FindItem(long start, const wxString& str, bool partial) |
2bda0e17 | 1091 | { |
0b5efdc7 | 1092 | LV_FINDINFO findInfo; |
2bda0e17 | 1093 | |
0b5efdc7 VZ |
1094 | findInfo.flags = LVFI_STRING; |
1095 | if ( partial ) | |
7edc258e | 1096 | findInfo.flags |= LVFI_PARTIAL; |
3ca6a5f0 | 1097 | findInfo.psz = str; |
2bda0e17 | 1098 | |
3ca6a5f0 BP |
1099 | // ListView_FindItem() excludes the first item from search and to look |
1100 | // through all the items you need to start from -1 which is unnatural and | |
8036af01 JS |
1101 | // inconsistent with the generic version - so we adjust the index |
1102 | if (start != -1) | |
1103 | start --; | |
1104 | return ListView_FindItem(GetHwnd(), (int) start, &findInfo); | |
2bda0e17 KB |
1105 | } |
1106 | ||
1107 | // Find an item whose data matches this data, starting from the item after 'start' | |
1108 | // or the beginning if 'start' is -1. | |
debe6624 | 1109 | long wxListCtrl::FindItem(long start, long data) |
2bda0e17 | 1110 | { |
0b5efdc7 | 1111 | LV_FINDINFO findInfo; |
2bda0e17 | 1112 | |
0b5efdc7 VZ |
1113 | findInfo.flags = LVFI_PARAM; |
1114 | findInfo.lParam = data; | |
2bda0e17 | 1115 | |
edccf428 | 1116 | return ListView_FindItem(GetHwnd(), (int) start, & findInfo); |
2bda0e17 KB |
1117 | } |
1118 | ||
1119 | // Find an item nearest this position in the specified direction, starting from | |
1120 | // the item after 'start' or the beginning if 'start' is -1. | |
debe6624 | 1121 | long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction) |
2bda0e17 | 1122 | { |
0b5efdc7 | 1123 | LV_FINDINFO findInfo; |
2bda0e17 | 1124 | |
0b5efdc7 VZ |
1125 | findInfo.flags = LVFI_NEARESTXY; |
1126 | findInfo.pt.x = pt.x; | |
1127 | findInfo.pt.y = pt.y; | |
acb62b84 | 1128 | findInfo.vkDirection = VK_RIGHT; |
2bda0e17 | 1129 | |
0b5efdc7 VZ |
1130 | if ( direction == wxLIST_FIND_UP ) |
1131 | findInfo.vkDirection = VK_UP; | |
1132 | else if ( direction == wxLIST_FIND_DOWN ) | |
1133 | findInfo.vkDirection = VK_DOWN; | |
1134 | else if ( direction == wxLIST_FIND_LEFT ) | |
1135 | findInfo.vkDirection = VK_LEFT; | |
1136 | else if ( direction == wxLIST_FIND_RIGHT ) | |
1137 | findInfo.vkDirection = VK_RIGHT; | |
1138 | ||
edccf428 | 1139 | return ListView_FindItem(GetHwnd(), (int) start, & findInfo); |
2bda0e17 KB |
1140 | } |
1141 | ||
1142 | // Determines which item (if any) is at the specified point, | |
1143 | // giving details in 'flags' (see wxLIST_HITTEST_... flags above) | |
1144 | long wxListCtrl::HitTest(const wxPoint& point, int& flags) | |
1145 | { | |
1146 | LV_HITTESTINFO hitTestInfo; | |
0b5efdc7 VZ |
1147 | hitTestInfo.pt.x = (int) point.x; |
1148 | hitTestInfo.pt.y = (int) point.y; | |
2bda0e17 | 1149 | |
edccf428 | 1150 | ListView_HitTest(GetHwnd(), & hitTestInfo); |
2bda0e17 | 1151 | |
0b5efdc7 VZ |
1152 | flags = 0; |
1153 | if ( hitTestInfo.flags & LVHT_ABOVE ) | |
1154 | flags |= wxLIST_HITTEST_ABOVE; | |
1155 | if ( hitTestInfo.flags & LVHT_BELOW ) | |
1156 | flags |= wxLIST_HITTEST_BELOW; | |
1157 | if ( hitTestInfo.flags & LVHT_NOWHERE ) | |
1158 | flags |= wxLIST_HITTEST_NOWHERE; | |
1159 | if ( hitTestInfo.flags & LVHT_ONITEMICON ) | |
1160 | flags |= wxLIST_HITTEST_ONITEMICON; | |
1161 | if ( hitTestInfo.flags & LVHT_ONITEMLABEL ) | |
1162 | flags |= wxLIST_HITTEST_ONITEMLABEL; | |
1163 | if ( hitTestInfo.flags & LVHT_ONITEMSTATEICON ) | |
1164 | flags |= wxLIST_HITTEST_ONITEMSTATEICON; | |
1165 | if ( hitTestInfo.flags & LVHT_TOLEFT ) | |
1166 | flags |= wxLIST_HITTEST_TOLEFT; | |
1167 | if ( hitTestInfo.flags & LVHT_TORIGHT ) | |
1168 | flags |= wxLIST_HITTEST_TORIGHT; | |
1169 | ||
edccf428 | 1170 | return (long) hitTestInfo.iItem; |
2bda0e17 KB |
1171 | } |
1172 | ||
1173 | // Inserts an item, returning the index of the new item if successful, | |
1174 | // -1 otherwise. | |
2bda0e17 KB |
1175 | long wxListCtrl::InsertItem(wxListItem& info) |
1176 | { | |
0b5efdc7 VZ |
1177 | LV_ITEM item; |
1178 | wxConvertToMSWListItem(this, info, item); | |
2bda0e17 | 1179 | |
bdc72a22 VZ |
1180 | // check whether it has any custom attributes |
1181 | if ( info.HasAttributes() ) | |
1182 | { | |
2702ed5a | 1183 | |
35ec54d3 VS |
1184 | wxListItemAttr *attr; |
1185 | attr = (wxListItemAttr*) m_attrs.Get(item.iItem); | |
2702ed5a | 1186 | |
35ec54d3 | 1187 | if (attr == NULL) |
2702ed5a | 1188 | |
35ec54d3 | 1189 | m_attrs.Put(item.iItem, (wxObject *)new wxListItemAttr(*info.GetAttributes())); |
2702ed5a | 1190 | |
35ec54d3 | 1191 | else *attr = *info.GetAttributes(); |
bdc72a22 VZ |
1192 | |
1193 | m_hasAnyAttr = TRUE; | |
1194 | } | |
bdc72a22 | 1195 | |
edccf428 | 1196 | return (long) ListView_InsertItem(GetHwnd(), & item); |
2bda0e17 KB |
1197 | } |
1198 | ||
debe6624 | 1199 | long wxListCtrl::InsertItem(long index, const wxString& label) |
2bda0e17 | 1200 | { |
0b5efdc7 VZ |
1201 | wxListItem info; |
1202 | info.m_text = label; | |
1203 | info.m_mask = wxLIST_MASK_TEXT; | |
1204 | info.m_itemId = index; | |
1205 | return InsertItem(info); | |
2bda0e17 KB |
1206 | } |
1207 | ||
1208 | // Inserts an image item | |
debe6624 | 1209 | long wxListCtrl::InsertItem(long index, int imageIndex) |
2bda0e17 | 1210 | { |
0b5efdc7 VZ |
1211 | wxListItem info; |
1212 | info.m_image = imageIndex; | |
1213 | info.m_mask = wxLIST_MASK_IMAGE; | |
1214 | info.m_itemId = index; | |
1215 | return InsertItem(info); | |
2bda0e17 KB |
1216 | } |
1217 | ||
1218 | // Inserts an image/string item | |
debe6624 | 1219 | long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex) |
2bda0e17 | 1220 | { |
0b5efdc7 VZ |
1221 | wxListItem info; |
1222 | info.m_image = imageIndex; | |
1223 | info.m_text = label; | |
1224 | info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT; | |
1225 | info.m_itemId = index; | |
1226 | return InsertItem(info); | |
2bda0e17 KB |
1227 | } |
1228 | ||
1229 | // For list view mode (only), inserts a column. | |
debe6624 | 1230 | long wxListCtrl::InsertColumn(long col, wxListItem& item) |
2bda0e17 | 1231 | { |
0b5efdc7 VZ |
1232 | LV_COLUMN lvCol; |
1233 | lvCol.mask = 0; | |
1234 | lvCol.fmt = 0; | |
1235 | lvCol.pszText = NULL; | |
1236 | ||
1237 | if ( item.m_mask & wxLIST_MASK_TEXT ) | |
1238 | { | |
1239 | lvCol.mask |= LVCF_TEXT; | |
1240 | lvCol.pszText = WXSTRINGCAST item.m_text; | |
1241 | lvCol.cchTextMax = 0; // Ignored | |
1242 | } | |
1243 | if ( item.m_mask & wxLIST_MASK_FORMAT ) | |
1244 | { | |
1245 | lvCol.mask |= LVCF_FMT; | |
1246 | ||
1247 | if ( item.m_format == wxLIST_FORMAT_LEFT ) | |
1248 | lvCol.fmt = LVCFMT_LEFT; | |
1249 | if ( item.m_format == wxLIST_FORMAT_RIGHT ) | |
1250 | lvCol.fmt = LVCFMT_RIGHT; | |
1251 | if ( item.m_format == wxLIST_FORMAT_CENTRE ) | |
1252 | lvCol.fmt = LVCFMT_CENTER; | |
2bda0e17 KB |
1253 | } |
1254 | ||
e373f51b | 1255 | lvCol.mask |= LVCF_WIDTH; |
0b5efdc7 VZ |
1256 | if ( item.m_mask & wxLIST_MASK_WIDTH ) |
1257 | { | |
e373f51b | 1258 | if ( item.m_width == wxLIST_AUTOSIZE) |
0b5efdc7 | 1259 | lvCol.cx = LVSCW_AUTOSIZE; |
e373f51b | 1260 | else if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER) |
0b5efdc7 | 1261 | lvCol.cx = LVSCW_AUTOSIZE_USEHEADER; |
e373f51b VZ |
1262 | else |
1263 | lvCol.cx = item.m_width; | |
1264 | } | |
1265 | else | |
1266 | { | |
1267 | // always give some width to the new column: this one is compatible | |
1268 | // with wxGTK | |
1269 | lvCol.cx = 80; | |
0b5efdc7 | 1270 | } |
e373f51b | 1271 | |
0b5efdc7 VZ |
1272 | lvCol.mask |= LVCF_SUBITEM; |
1273 | lvCol.iSubItem = col; | |
2bda0e17 | 1274 | |
edccf428 | 1275 | bool success = ListView_InsertColumn(GetHwnd(), col, & lvCol) != -1; |
2bda0e17 | 1276 | if ( success ) |
e373f51b VZ |
1277 | { |
1278 | m_colCount++; | |
1279 | } | |
1280 | else | |
1281 | { | |
223d09f6 | 1282 | wxLogDebug(wxT("Failed to insert the column '%s' into listview!"), |
e373f51b VZ |
1283 | lvCol.pszText); |
1284 | } | |
1285 | ||
2bda0e17 KB |
1286 | return success; |
1287 | } | |
1288 | ||
bdc72a22 VZ |
1289 | long wxListCtrl::InsertColumn(long col, |
1290 | const wxString& heading, | |
1291 | int format, | |
1292 | int width) | |
2bda0e17 | 1293 | { |
0b5efdc7 VZ |
1294 | wxListItem item; |
1295 | item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT; | |
1296 | item.m_text = heading; | |
1297 | if ( width > -1 ) | |
1298 | { | |
1299 | item.m_mask |= wxLIST_MASK_WIDTH; | |
1300 | item.m_width = width; | |
1301 | } | |
1302 | item.m_format = format; | |
2bda0e17 | 1303 | |
0b5efdc7 | 1304 | return InsertColumn(col, item); |
2bda0e17 KB |
1305 | } |
1306 | ||
1307 | // Scrolls the list control. If in icon, small icon or report view mode, | |
1308 | // x specifies the number of pixels to scroll. If in list view mode, x | |
1309 | // specifies the number of columns to scroll. | |
1310 | // If in icon, small icon or list view mode, y specifies the number of pixels | |
1311 | // to scroll. If in report view mode, y specifies the number of lines to scroll. | |
debe6624 | 1312 | bool wxListCtrl::ScrollList(int dx, int dy) |
2bda0e17 | 1313 | { |
edccf428 | 1314 | return (ListView_Scroll(GetHwnd(), dx, dy) != 0); |
2bda0e17 KB |
1315 | } |
1316 | ||
1317 | // Sort items. | |
1318 | ||
1319 | // fn is a function which takes 3 long arguments: item1, item2, data. | |
1320 | // item1 is the long data associated with a first item (NOT the index). | |
1321 | // item2 is the long data associated with a second item (NOT the index). | |
1322 | // data is the same value as passed to SortItems. | |
1323 | // The return value is a negative number if the first item should precede the second | |
1324 | // item, a positive number of the second item should precede the first, | |
1325 | // or zero if the two items are equivalent. | |
1326 | ||
1327 | // data is arbitrary data to be passed to the sort function. | |
1328 | bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data) | |
1329 | { | |
edccf428 | 1330 | return (ListView_SortItems(GetHwnd(), (PFNLVCOMPARE) fn, data) != 0); |
2bda0e17 KB |
1331 | } |
1332 | ||
edccf428 VZ |
1333 | // ---------------------------------------------------------------------------- |
1334 | // message processing | |
1335 | // ---------------------------------------------------------------------------- | |
1336 | ||
debe6624 | 1337 | bool wxListCtrl::MSWCommand(WXUINT cmd, WXWORD id) |
2bda0e17 | 1338 | { |
0b5efdc7 | 1339 | if (cmd == EN_UPDATE) |
acb62b84 | 1340 | { |
0b5efdc7 VZ |
1341 | wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, id); |
1342 | event.SetEventObject( this ); | |
1343 | ProcessCommand(event); | |
1344 | return TRUE; | |
acb62b84 | 1345 | } |
0b5efdc7 | 1346 | else if (cmd == EN_KILLFOCUS) |
acb62b84 | 1347 | { |
0b5efdc7 VZ |
1348 | wxCommandEvent event(wxEVT_KILL_FOCUS, id); |
1349 | event.SetEventObject( this ); | |
1350 | ProcessCommand(event); | |
1351 | return TRUE; | |
acb62b84 | 1352 | } |
edccf428 VZ |
1353 | else |
1354 | return FALSE; | |
0b5efdc7 VZ |
1355 | } |
1356 | ||
a23fd0e1 | 1357 | bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) |
0b5efdc7 | 1358 | { |
bdc72a22 VZ |
1359 | // prepare the event |
1360 | // ----------------- | |
1361 | ||
0b5efdc7 VZ |
1362 | wxListEvent event(wxEVT_NULL, m_windowId); |
1363 | wxEventType eventType = wxEVT_NULL; | |
225fe9d6 | 1364 | |
bdc72a22 | 1365 | NMHDR *nmhdr = (NMHDR *)lParam; |
225fe9d6 VZ |
1366 | |
1367 | // almost all messages use NM_LISTVIEW | |
1368 | NM_LISTVIEW *nmLV = (NM_LISTVIEW *)nmhdr; | |
1369 | ||
1370 | // this is true for almost all events | |
1371 | event.m_item.m_data = nmLV->lParam; | |
1372 | ||
bdc72a22 | 1373 | switch ( nmhdr->code ) |
acb62b84 | 1374 | { |
0b5efdc7 | 1375 | case LVN_BEGINRDRAG: |
bdc72a22 | 1376 | eventType = wxEVT_COMMAND_LIST_BEGIN_RDRAG; |
0b5efdc7 | 1377 | // fall through |
cb0f56f9 | 1378 | |
0b5efdc7 VZ |
1379 | case LVN_BEGINDRAG: |
1380 | if ( eventType == wxEVT_NULL ) | |
1381 | { | |
1382 | eventType = wxEVT_COMMAND_LIST_BEGIN_DRAG; | |
1383 | } | |
1384 | ||
225fe9d6 VZ |
1385 | event.m_itemIndex = nmLV->iItem; |
1386 | event.m_pointDrag.x = nmLV->ptAction.x; | |
1387 | event.m_pointDrag.y = nmLV->ptAction.y; | |
0b5efdc7 VZ |
1388 | break; |
1389 | ||
1390 | case LVN_BEGINLABELEDIT: | |
1391 | { | |
1392 | eventType = wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT; | |
1393 | LV_DISPINFO *info = (LV_DISPINFO *)lParam; | |
edccf428 | 1394 | wxConvertFromMSWListItem(this, event.m_item, info->item, GetHwnd()); |
0b5efdc7 | 1395 | } |
225fe9d6 | 1396 | break; |
0b5efdc7 VZ |
1397 | |
1398 | case LVN_COLUMNCLICK: | |
225fe9d6 VZ |
1399 | eventType = wxEVT_COMMAND_LIST_COL_CLICK; |
1400 | event.m_itemIndex = -1; | |
1401 | event.m_col = nmLV->iSubItem; | |
1402 | break; | |
5ea47806 | 1403 | |
0b5efdc7 | 1404 | case LVN_DELETEALLITEMS: |
6932a32c | 1405 | eventType = wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS; |
5ea47806 | 1406 | event.m_itemIndex = -1; |
5ea47806 | 1407 | |
6932a32c | 1408 | FreeAllAttrs(); |
bdc72a22 | 1409 | |
6932a32c | 1410 | break; |
5ea47806 | 1411 | |
0b5efdc7 | 1412 | case LVN_DELETEITEM: |
225fe9d6 VZ |
1413 | eventType = wxEVT_COMMAND_LIST_DELETE_ITEM; |
1414 | event.m_itemIndex = nmLV->iItem; | |
bdc72a22 | 1415 | |
225fe9d6 VZ |
1416 | if ( m_hasAnyAttr ) |
1417 | { | |
1418 | delete (wxListItemAttr *)m_attrs.Delete(nmLV->iItem); | |
0b5efdc7 | 1419 | } |
bdc72a22 VZ |
1420 | break; |
1421 | ||
0b5efdc7 VZ |
1422 | case LVN_ENDLABELEDIT: |
1423 | { | |
1424 | eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT; | |
1425 | LV_DISPINFO *info = (LV_DISPINFO *)lParam; | |
1ee4ead5 | 1426 | wxConvertFromMSWListItem(this, event.m_item, info->item); |
0b5efdc7 | 1427 | if ( info->item.pszText == NULL || info->item.iItem == -1 ) |
1ee4ead5 | 1428 | return FALSE; |
0b5efdc7 | 1429 | } |
bdc72a22 VZ |
1430 | break; |
1431 | ||
1432 | case LVN_SETDISPINFO: | |
1433 | { | |
1434 | eventType = wxEVT_COMMAND_LIST_SET_INFO; | |
1435 | LV_DISPINFO *info = (LV_DISPINFO *)lParam; | |
1436 | wxConvertFromMSWListItem(this, event.m_item, info->item, GetHwnd()); | |
1437 | } | |
1438 | break; | |
edccf428 | 1439 | |
bdc72a22 | 1440 | case LVN_GETDISPINFO: |
edccf428 VZ |
1441 | // this provokes stack overflow: indeed, wxConvertFromMSWListItem() |
1442 | // sends us WM_NOTIFY! As it doesn't do anything for now, just leave | |
1443 | // it out. | |
1444 | #if 0 | |
0b5efdc7 | 1445 | { |
0b5efdc7 VZ |
1446 | // TODO: some text buffering here, I think |
1447 | // TODO: API for getting Windows to retrieve values | |
1448 | // on demand. | |
1449 | eventType = wxEVT_COMMAND_LIST_GET_INFO; | |
1450 | LV_DISPINFO *info = (LV_DISPINFO *)lParam; | |
edccf428 | 1451 | wxConvertFromMSWListItem(this, event.m_item, info->item, GetHwnd()); |
0b5efdc7 VZ |
1452 | break; |
1453 | } | |
edccf428 | 1454 | #endif // 0 |
bdc72a22 VZ |
1455 | return FALSE; |
1456 | ||
edccf428 | 1457 | |
0b5efdc7 | 1458 | case LVN_INSERTITEM: |
225fe9d6 VZ |
1459 | eventType = wxEVT_COMMAND_LIST_INSERT_ITEM; |
1460 | event.m_itemIndex = nmLV->iItem; | |
1461 | break; | |
bdc72a22 | 1462 | |
0b5efdc7 | 1463 | case LVN_ITEMCHANGED: |
225fe9d6 VZ |
1464 | // This needs to be sent to wxListCtrl as a rather more concrete |
1465 | // event. For now, just detect a selection or deselection. | |
1466 | if ( (nmLV->uNewState & LVIS_SELECTED) && !(nmLV->uOldState & LVIS_SELECTED) ) | |
0b5efdc7 | 1467 | { |
225fe9d6 VZ |
1468 | eventType = wxEVT_COMMAND_LIST_ITEM_SELECTED; |
1469 | event.m_itemIndex = nmLV->iItem; | |
1470 | } | |
1471 | else if ( !(nmLV->uNewState & LVIS_SELECTED) && (nmLV->uOldState & LVIS_SELECTED) ) | |
1472 | { | |
1473 | eventType = wxEVT_COMMAND_LIST_ITEM_DESELECTED; | |
1474 | event.m_itemIndex = nmLV->iItem; | |
0b5efdc7 | 1475 | } |
225fe9d6 VZ |
1476 | else |
1477 | { | |
1478 | return FALSE; | |
1479 | } | |
1480 | break; | |
edccf428 | 1481 | |
0b5efdc7 VZ |
1482 | case LVN_KEYDOWN: |
1483 | { | |
0b5efdc7 | 1484 | LV_KEYDOWN *info = (LV_KEYDOWN *)lParam; |
edccf428 VZ |
1485 | WORD wVKey = info->wVKey; |
1486 | ||
1487 | // get the current selection | |
1488 | long lItem = GetNextItem(-1, | |
1489 | wxLIST_NEXT_ALL, | |
1490 | wxLIST_STATE_SELECTED); | |
1491 | ||
d8408fc6 VZ |
1492 | // <Enter> or <Space> activate the selected item if any (but |
1493 | // not with Shift and/or Ctrl as then they have a predefined | |
1494 | // meaning for the list view) | |
1495 | if ( lItem != -1 && | |
1496 | (wVKey == VK_RETURN || wVKey == VK_SPACE) && | |
1497 | !(wxIsShiftDown() || wxIsCtrlDown()) ) | |
edccf428 | 1498 | { |
edccf428 VZ |
1499 | eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED; |
1500 | event.m_itemIndex = lItem; | |
1501 | } | |
1502 | else | |
1503 | { | |
1504 | eventType = wxEVT_COMMAND_LIST_KEY_DOWN; | |
1505 | event.m_code = wxCharCodeMSWToWX(wVKey); | |
1506 | } | |
225fe9d6 | 1507 | |
f6bcfd97 BP |
1508 | if ( lItem != -1 ) |
1509 | { | |
1510 | // fill the other fields too | |
1511 | event.m_item.m_text = GetItemText(lItem); | |
1512 | event.m_item.m_data = GetItemData(lItem); | |
1513 | } | |
0b5efdc7 | 1514 | } |
225fe9d6 | 1515 | break; |
edccf428 VZ |
1516 | |
1517 | case NM_DBLCLK: | |
1518 | // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do | |
1519 | // anything else | |
1520 | if ( wxControl::MSWOnNotify(idCtrl, lParam, result) ) | |
1521 | { | |
1522 | return TRUE; | |
1523 | } | |
1524 | ||
1525 | // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event | |
5bd3a2da | 1526 | // if it happened on an item (and not on empty place) |
225fe9d6 | 1527 | if ( nmLV->iItem == -1 ) |
1ee4ead5 | 1528 | { |
225fe9d6 VZ |
1529 | // not on item |
1530 | return FALSE; | |
1ee4ead5 | 1531 | } |
225fe9d6 VZ |
1532 | |
1533 | eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED; | |
1534 | event.m_itemIndex = nmLV->iItem; | |
f6bcfd97 | 1535 | event.m_item.m_text = GetItemText(nmLV->iItem); |
225fe9d6 | 1536 | event.m_item.m_data = GetItemData(nmLV->iItem); |
edccf428 | 1537 | break; |
cb0f56f9 VZ |
1538 | |
1539 | case NM_RCLICK: | |
225fe9d6 VZ |
1540 | /* TECH NOTE: NM_RCLICK isn't really good enough here. We want to |
1541 | subclass and check for the actual WM_RBUTTONDOWN message, | |
1542 | because NM_RCLICK waits for the WM_RBUTTONUP message as well | |
1543 | before firing off. We want to have notify events for both down | |
1544 | -and- up. */ | |
1545 | { | |
1546 | // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(), | |
1547 | // don't do anything else | |
1548 | if ( wxControl::MSWOnNotify(idCtrl, lParam, result) ) | |
1549 | { | |
1550 | return TRUE; | |
1551 | } | |
cb0f56f9 | 1552 | |
225fe9d6 VZ |
1553 | // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event |
1554 | LV_HITTESTINFO lvhti; | |
1555 | wxZeroMemory(lvhti); | |
11c7d5b6 | 1556 | |
225fe9d6 VZ |
1557 | ::GetCursorPos(&(lvhti.pt)); |
1558 | ::ScreenToClient(GetHwnd(),&(lvhti.pt)); | |
1559 | if ( ListView_HitTest(GetHwnd(),&lvhti) != -1 ) | |
cb0f56f9 | 1560 | { |
225fe9d6 VZ |
1561 | if ( lvhti.flags & LVHT_ONITEM ) |
1562 | { | |
1563 | eventType = wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK; | |
1564 | event.m_itemIndex = lvhti.iItem; | |
a1f79c1e VZ |
1565 | event.m_pointDrag.x = lvhti.pt.x; |
1566 | event.m_pointDrag.y = lvhti.pt.y; | |
225fe9d6 | 1567 | } |
cb0f56f9 | 1568 | } |
9bfa7bfc | 1569 | } |
cb0f56f9 VZ |
1570 | break; |
1571 | ||
bdc72a22 VZ |
1572 | #if 0 |
1573 | case NM_MCLICK: // ***** THERE IS NO NM_MCLICK. Subclass anyone? ****** | |
1574 | { | |
1575 | // if the user processes it in wxEVT_COMMAND_MIDDLE_CLICK(), don't do | |
1576 | // anything else | |
1577 | if ( wxControl::MSWOnNotify(idCtrl, lParam, result) ) | |
1578 | { | |
1579 | return TRUE; | |
1580 | } | |
cb0f56f9 | 1581 | |
bdc72a22 VZ |
1582 | // else translate it into wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK event |
1583 | eventType = wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK; | |
1584 | NMITEMACTIVATE* hdr = (NMITEMACTIVATE*)lParam; | |
1585 | event.m_itemIndex = hdr->iItem; | |
1586 | } | |
1587 | break; | |
1588 | #endif // 0 | |
1589 | ||
6ecfe2ac | 1590 | #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 |
bdc72a22 | 1591 | case NM_CUSTOMDRAW: |
0b5efdc7 | 1592 | { |
bdc72a22 VZ |
1593 | LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam; |
1594 | NMCUSTOMDRAW& nmcd = lplvcd->nmcd; | |
1595 | switch( nmcd.dwDrawStage ) | |
1596 | { | |
d62228a6 | 1597 | case CDDS_PREPAINT: |
bdc72a22 VZ |
1598 | // if we've got any items with non standard attributes, |
1599 | // notify us before painting each item | |
1600 | *result = m_hasAnyAttr ? CDRF_NOTIFYITEMDRAW | |
1601 | : CDRF_DODEFAULT; | |
1602 | return TRUE; | |
1603 | ||
1604 | case CDDS_ITEMPREPAINT: | |
1605 | { | |
d62228a6 VZ |
1606 | wxListItemAttr *attr = |
1607 | (wxListItemAttr *)m_attrs.Get(nmcd.dwItemSpec); | |
1608 | ||
1609 | if ( !attr ) | |
bdc72a22 VZ |
1610 | { |
1611 | // nothing to do for this item | |
1612 | return CDRF_DODEFAULT; | |
1613 | } | |
1614 | ||
d62228a6 VZ |
1615 | HFONT hFont; |
1616 | wxColour colText, colBack; | |
1617 | if ( attr->HasFont() ) | |
1618 | { | |
1619 | wxFont font = attr->GetFont(); | |
1620 | hFont = (HFONT)font.GetResourceHandle(); | |
1621 | } | |
1622 | else | |
1623 | { | |
1624 | hFont = 0; | |
1625 | } | |
1626 | ||
1627 | if ( attr->HasTextColour() ) | |
1628 | { | |
1629 | colText = attr->GetTextColour(); | |
1630 | } | |
1631 | else | |
1632 | { | |
1633 | colText = GetTextColour(); | |
1634 | } | |
1635 | ||
1636 | if ( attr->HasBackgroundColour() ) | |
1637 | { | |
1638 | colBack = attr->GetBackgroundColour(); | |
1639 | } | |
1640 | else | |
1641 | { | |
1642 | colBack = GetBackgroundColour(); | |
1643 | } | |
1644 | ||
1645 | // note that if we wanted to set colours for | |
1646 | // individual columns (subitems), we would have | |
1647 | // returned CDRF_NOTIFYSUBITEMREDRAW from here | |
1648 | if ( hFont ) | |
1649 | { | |
1650 | ::SelectObject(nmcd.hdc, hFont); | |
bdc72a22 | 1651 | |
d62228a6 VZ |
1652 | *result = CDRF_NEWFONT; |
1653 | } | |
1654 | else | |
1655 | { | |
1656 | *result = CDRF_DODEFAULT; | |
1657 | } | |
bdc72a22 | 1658 | |
d62228a6 VZ |
1659 | lplvcd->clrText = wxColourToRGB(colText); |
1660 | lplvcd->clrTextBk = wxColourToRGB(colBack); | |
bdc72a22 VZ |
1661 | |
1662 | return TRUE; | |
1663 | } | |
d62228a6 VZ |
1664 | |
1665 | default: | |
1666 | *result = CDRF_DODEFAULT; | |
1667 | return TRUE; | |
bdc72a22 | 1668 | } |
0b5efdc7 | 1669 | } |
3897b707 | 1670 | // break; // can never be reached |
6ecfe2ac | 1671 | #endif // _WIN32_IE >= 0x300 |
0b5efdc7 | 1672 | |
edccf428 | 1673 | default: |
a23fd0e1 | 1674 | return wxControl::MSWOnNotify(idCtrl, lParam, result); |
acb62b84 VZ |
1675 | } |
1676 | ||
bdc72a22 VZ |
1677 | // process the event |
1678 | // ----------------- | |
1679 | ||
0b5efdc7 VZ |
1680 | event.SetEventObject( this ); |
1681 | event.SetEventType(eventType); | |
acb62b84 | 1682 | |
0b5efdc7 VZ |
1683 | if ( !GetEventHandler()->ProcessEvent(event) ) |
1684 | return FALSE; | |
acb62b84 | 1685 | |
bdc72a22 VZ |
1686 | // post processing |
1687 | // --------------- | |
1688 | ||
225fe9d6 | 1689 | switch ( nmhdr->code ) |
acb62b84 | 1690 | { |
6932a32c VZ |
1691 | case LVN_DELETEALLITEMS: |
1692 | // always return TRUE to suppress all additional LVN_DELETEITEM | |
1693 | // notifications - this makes deleting all items from a list ctrl | |
1694 | // much faster | |
1695 | *result = TRUE; | |
1696 | ||
1697 | return TRUE; | |
1698 | ||
1ee4ead5 | 1699 | case LVN_GETDISPINFO: |
0b5efdc7 | 1700 | { |
1ee4ead5 VZ |
1701 | LV_DISPINFO *info = (LV_DISPINFO *)lParam; |
1702 | if ( info->item.mask & LVIF_TEXT ) | |
1703 | { | |
1704 | if ( !event.m_item.m_text.IsNull() ) | |
1705 | { | |
1706 | info->item.pszText = AddPool(event.m_item.m_text); | |
1707 | info->item.cchTextMax = wxStrlen(info->item.pszText) + 1; | |
1708 | } | |
1709 | } | |
1710 | // wxConvertToMSWListItem(this, event.m_item, info->item); | |
1711 | break; | |
0b5efdc7 | 1712 | } |
1ee4ead5 VZ |
1713 | case LVN_ENDLABELEDIT: |
1714 | { | |
1715 | *result = event.IsAllowed(); | |
1716 | return TRUE; | |
1717 | } | |
acb62b84 | 1718 | } |
acb62b84 | 1719 | |
0b5efdc7 | 1720 | *result = !event.IsAllowed(); |
fd3f686c | 1721 | |
0b5efdc7 | 1722 | return TRUE; |
2bda0e17 KB |
1723 | } |
1724 | ||
837e5743 | 1725 | wxChar *wxListCtrl::AddPool(const wxString& str) |
2bda0e17 | 1726 | { |
0b5efdc7 VZ |
1727 | // Remove the first element if 3 strings exist |
1728 | if ( m_stringPool.Number() == 3 ) | |
1729 | { | |
1730 | wxNode *node = m_stringPool.First(); | |
1731 | delete[] (char *)node->Data(); | |
1732 | delete node; | |
1733 | } | |
837e5743 OK |
1734 | wxNode *node = m_stringPool.Add(WXSTRINGCAST str); |
1735 | return (wxChar *)node->Data(); | |
2bda0e17 KB |
1736 | } |
1737 | ||
2702ed5a JS |
1738 | // Necessary for drawing hrules and vrules, if specified |
1739 | void wxListCtrl::OnPaint(wxPaintEvent& event) | |
1740 | { | |
1741 | wxPaintDC dc(this); | |
1742 | ||
1743 | wxControl::OnPaint(event); | |
1744 | ||
1745 | // Reset the device origin since it may have been set | |
1746 | dc.SetDeviceOrigin(0, 0); | |
1747 | ||
1748 | bool drawHRules = ((GetWindowStyle() & wxLC_HRULES) != 0); | |
1749 | bool drawVRules = ((GetWindowStyle() & wxLC_VRULES) != 0); | |
1750 | ||
1751 | if (!drawHRules && !drawVRules) | |
1752 | return; | |
1753 | if ((GetWindowStyle() & wxLC_REPORT) == 0) | |
1754 | return; | |
1755 | ||
1756 | wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID); | |
1757 | dc.SetPen(pen); | |
1758 | dc.SetBrush(* wxTRANSPARENT_BRUSH); | |
1759 | ||
1760 | wxSize clientSize = GetClientSize(); | |
1761 | wxRect itemRect; | |
1762 | int cy=0; | |
1763 | ||
2702ed5a JS |
1764 | int itemCount = GetItemCount(); |
1765 | int i; | |
1766 | for (i = 0; i < itemCount; i++) | |
1767 | { | |
1768 | if (GetItemRect(i, itemRect)) | |
1769 | { | |
1770 | cy = itemRect.GetTop(); | |
1771 | if (i != 0) // Don't draw the first one | |
1772 | { | |
1773 | dc.DrawLine(0, cy, clientSize.x, cy); | |
ca286917 JS |
1774 | } |
1775 | // Draw last line | |
1776 | if (i == (GetItemCount() - 1)) | |
1777 | { | |
1778 | cy = itemRect.GetBottom(); | |
1779 | dc.DrawLine(0, cy, clientSize.x, cy); | |
2702ed5a JS |
1780 | } |
1781 | } | |
1782 | } | |
1783 | i = (GetItemCount() - 1); | |
1784 | if (drawVRules && (i > -1)) | |
1785 | { | |
1786 | wxRect firstItemRect; | |
1787 | GetItemRect(0, firstItemRect); | |
1788 | ||
1789 | if (GetItemRect(i, itemRect)) | |
1790 | { | |
1791 | int col; | |
1792 | int x = itemRect.GetX(); | |
1793 | for (col = 0; col < GetColumnCount(); col++) | |
1794 | { | |
1795 | int colWidth = GetColumnWidth(col); | |
1796 | x += colWidth ; | |
1797 | dc.DrawLine(x, firstItemRect.GetY() - 2, x, itemRect.GetBottom()); | |
1798 | } | |
1799 | } | |
1800 | } | |
1801 | } | |
1802 | ||
edccf428 VZ |
1803 | // ---------------------------------------------------------------------------- |
1804 | // wxListItem | |
1805 | // ---------------------------------------------------------------------------- | |
1806 | ||
2bda0e17 | 1807 | // List item structure |
0b5efdc7 | 1808 | wxListItem::wxListItem() |
2bda0e17 KB |
1809 | { |
1810 | m_mask = 0; | |
1811 | m_itemId = 0; | |
1812 | m_col = 0; | |
1813 | m_state = 0; | |
1814 | m_stateMask = 0; | |
1815 | m_image = 0; | |
0b5efdc7 | 1816 | m_data = 0; |
2bda0e17 | 1817 | |
0b5efdc7 VZ |
1818 | m_format = wxLIST_FORMAT_CENTRE; |
1819 | m_width = 0; | |
bdc72a22 VZ |
1820 | |
1821 | m_attr = NULL; | |
2bda0e17 KB |
1822 | } |
1823 | ||
9b00bb16 RR |
1824 | void wxListItem::Clear() |
1825 | { | |
1826 | m_mask = 0; | |
1827 | m_itemId = 0; | |
1828 | m_col = 0; | |
1829 | m_state = 0; | |
1830 | m_stateMask = 0; | |
1831 | m_image = 0; | |
1832 | m_data = 0; | |
1833 | m_format = wxLIST_FORMAT_CENTRE; | |
1834 | m_width = 0; | |
1835 | m_text = wxEmptyString; | |
1836 | ||
1837 | if (m_attr) delete m_attr; | |
1838 | m_attr = NULL; | |
1839 | } | |
1840 | ||
1841 | void wxListItem::ClearAttributes() | |
1842 | { | |
1843 | if (m_attr) delete m_attr; | |
1844 | m_attr = NULL; | |
1845 | } | |
1846 | ||
33ac7e6f | 1847 | static void wxConvertFromMSWListItem(const wxListCtrl *WXUNUSED(ctrl), wxListItem& info, LV_ITEM& lvItem, HWND getFullInfo) |
2bda0e17 | 1848 | { |
0b5efdc7 VZ |
1849 | info.m_data = lvItem.lParam; |
1850 | info.m_mask = 0; | |
1851 | info.m_state = 0; | |
1852 | info.m_stateMask = 0; | |
1853 | info.m_itemId = lvItem.iItem; | |
acb62b84 | 1854 | |
0b5efdc7 | 1855 | long oldMask = lvItem.mask; |
acb62b84 | 1856 | |
0b5efdc7 VZ |
1857 | bool needText = FALSE; |
1858 | if (getFullInfo != 0) | |
acb62b84 | 1859 | { |
0b5efdc7 VZ |
1860 | if ( lvItem.mask & LVIF_TEXT ) |
1861 | needText = FALSE; | |
1862 | else | |
1863 | needText = TRUE; | |
acb62b84 | 1864 | |
0b5efdc7 VZ |
1865 | if ( needText ) |
1866 | { | |
837e5743 | 1867 | lvItem.pszText = new wxChar[513]; |
0b5efdc7 VZ |
1868 | lvItem.cchTextMax = 512; |
1869 | } | |
edccf428 VZ |
1870 | // lvItem.mask |= TVIF_HANDLE | TVIF_STATE | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM; |
1871 | lvItem.mask |= LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM; | |
1872 | ::SendMessage(getFullInfo, LVM_GETITEM, 0, (LPARAM)& lvItem); | |
0b5efdc7 | 1873 | } |
acb62b84 | 1874 | |
0b5efdc7 | 1875 | if ( lvItem.mask & LVIF_STATE ) |
acb62b84 | 1876 | { |
0b5efdc7 VZ |
1877 | info.m_mask |= wxLIST_MASK_STATE; |
1878 | ||
1879 | if ( lvItem.stateMask & LVIS_CUT) | |
1880 | { | |
edccf428 | 1881 | info.m_stateMask |= wxLIST_STATE_CUT; |
0b5efdc7 | 1882 | if ( lvItem.state & LVIS_CUT ) |
edccf428 | 1883 | info.m_state |= wxLIST_STATE_CUT; |
0b5efdc7 VZ |
1884 | } |
1885 | if ( lvItem.stateMask & LVIS_DROPHILITED) | |
1886 | { | |
edccf428 | 1887 | info.m_stateMask |= wxLIST_STATE_DROPHILITED; |
0b5efdc7 | 1888 | if ( lvItem.state & LVIS_DROPHILITED ) |
edccf428 | 1889 | info.m_state |= wxLIST_STATE_DROPHILITED; |
0b5efdc7 VZ |
1890 | } |
1891 | if ( lvItem.stateMask & LVIS_FOCUSED) | |
1892 | { | |
edccf428 | 1893 | info.m_stateMask |= wxLIST_STATE_FOCUSED; |
0b5efdc7 | 1894 | if ( lvItem.state & LVIS_FOCUSED ) |
edccf428 | 1895 | info.m_state |= wxLIST_STATE_FOCUSED; |
0b5efdc7 VZ |
1896 | } |
1897 | if ( lvItem.stateMask & LVIS_SELECTED) | |
1898 | { | |
edccf428 | 1899 | info.m_stateMask |= wxLIST_STATE_SELECTED; |
0b5efdc7 | 1900 | if ( lvItem.state & LVIS_SELECTED ) |
edccf428 | 1901 | info.m_state |= wxLIST_STATE_SELECTED; |
0b5efdc7 | 1902 | } |
acb62b84 | 1903 | } |
0b5efdc7 VZ |
1904 | |
1905 | if ( lvItem.mask & LVIF_TEXT ) | |
acb62b84 | 1906 | { |
0b5efdc7 VZ |
1907 | info.m_mask |= wxLIST_MASK_TEXT; |
1908 | info.m_text = lvItem.pszText; | |
acb62b84 | 1909 | } |
0b5efdc7 | 1910 | if ( lvItem.mask & LVIF_IMAGE ) |
acb62b84 | 1911 | { |
0b5efdc7 VZ |
1912 | info.m_mask |= wxLIST_MASK_IMAGE; |
1913 | info.m_image = lvItem.iImage; | |
acb62b84 | 1914 | } |
0b5efdc7 VZ |
1915 | if ( lvItem.mask & LVIF_PARAM ) |
1916 | info.m_mask |= wxLIST_MASK_DATA; | |
1917 | if ( lvItem.mask & LVIF_DI_SETITEM ) | |
1918 | info.m_mask |= wxLIST_SET_ITEM; | |
1919 | info.m_col = lvItem.iSubItem; | |
1920 | ||
1921 | if (needText) | |
acb62b84 | 1922 | { |
0b5efdc7 VZ |
1923 | if (lvItem.pszText) |
1924 | delete[] lvItem.pszText; | |
acb62b84 | 1925 | } |
edccf428 | 1926 | lvItem.mask = oldMask; |
2bda0e17 KB |
1927 | } |
1928 | ||
1929 | static void wxConvertToMSWListItem(const wxListCtrl *ctrl, wxListItem& info, LV_ITEM& lvItem) | |
1930 | { | |
edccf428 | 1931 | lvItem.iItem = (int) info.m_itemId; |
acb62b84 | 1932 | |
edccf428 | 1933 | lvItem.iImage = info.m_image; |
0b5efdc7 VZ |
1934 | lvItem.lParam = info.m_data; |
1935 | lvItem.stateMask = 0; | |
1936 | lvItem.state = 0; | |
1937 | lvItem.mask = 0; | |
1938 | lvItem.iSubItem = info.m_col; | |
acb62b84 | 1939 | |
0b5efdc7 | 1940 | if (info.m_mask & wxLIST_MASK_STATE) |
acb62b84 | 1941 | { |
edccf428 | 1942 | lvItem.mask |= LVIF_STATE; |
0b5efdc7 VZ |
1943 | if (info.m_stateMask & wxLIST_STATE_CUT) |
1944 | { | |
edccf428 | 1945 | lvItem.stateMask |= LVIS_CUT; |
0b5efdc7 VZ |
1946 | if (info.m_state & wxLIST_STATE_CUT) |
1947 | lvItem.state |= LVIS_CUT; | |
1948 | } | |
1949 | if (info.m_stateMask & wxLIST_STATE_DROPHILITED) | |
1950 | { | |
1951 | lvItem.stateMask |= LVIS_DROPHILITED; | |
1952 | if (info.m_state & wxLIST_STATE_DROPHILITED) | |
1953 | lvItem.state |= LVIS_DROPHILITED; | |
1954 | } | |
1955 | if (info.m_stateMask & wxLIST_STATE_FOCUSED) | |
1956 | { | |
1957 | lvItem.stateMask |= LVIS_FOCUSED; | |
1958 | if (info.m_state & wxLIST_STATE_FOCUSED) | |
1959 | lvItem.state |= LVIS_FOCUSED; | |
1960 | } | |
1961 | if (info.m_stateMask & wxLIST_STATE_SELECTED) | |
1962 | { | |
1963 | lvItem.stateMask |= LVIS_SELECTED; | |
1964 | if (info.m_state & wxLIST_STATE_SELECTED) | |
1965 | lvItem.state |= LVIS_SELECTED; | |
1966 | } | |
acb62b84 | 1967 | } |
acb62b84 | 1968 | |
0b5efdc7 | 1969 | if (info.m_mask & wxLIST_MASK_TEXT) |
acb62b84 | 1970 | { |
edccf428 | 1971 | lvItem.mask |= LVIF_TEXT; |
0b5efdc7 VZ |
1972 | if ( ctrl->GetWindowStyleFlag() & wxLC_USER_TEXT ) |
1973 | { | |
1974 | lvItem.pszText = LPSTR_TEXTCALLBACK; | |
1975 | } | |
1976 | else | |
1977 | { | |
edccf428 | 1978 | lvItem.pszText = WXSTRINGCAST info.m_text; |
0b5efdc7 VZ |
1979 | if ( lvItem.pszText ) |
1980 | lvItem.cchTextMax = info.m_text.Length(); | |
1981 | else | |
1982 | lvItem.cchTextMax = 0; | |
1983 | } | |
acb62b84 | 1984 | } |
0b5efdc7 | 1985 | if (info.m_mask & wxLIST_MASK_IMAGE) |
edccf428 | 1986 | lvItem.mask |= LVIF_IMAGE; |
0b5efdc7 | 1987 | if (info.m_mask & wxLIST_MASK_DATA) |
edccf428 | 1988 | lvItem.mask |= LVIF_PARAM; |
2bda0e17 KB |
1989 | } |
1990 | ||
edccf428 | 1991 | // ---------------------------------------------------------------------------- |
2bda0e17 | 1992 | // List event |
edccf428 VZ |
1993 | // ---------------------------------------------------------------------------- |
1994 | ||
92976ab6 | 1995 | IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent) |
2bda0e17 | 1996 | |
fd3f686c | 1997 | wxListEvent::wxListEvent(wxEventType commandType, int id) |
edccf428 | 1998 | : wxNotifyEvent(commandType, id) |
2bda0e17 | 1999 | { |
0b5efdc7 VZ |
2000 | m_code = 0; |
2001 | m_itemIndex = 0; | |
5d47c8a0 | 2002 | m_oldItemIndex = 0; |
0b5efdc7 VZ |
2003 | m_col = 0; |
2004 | m_cancelled = FALSE; | |
2bda0e17 KB |
2005 | } |
2006 | ||
edccf428 | 2007 | #endif // __WIN95__ |
2bda0e17 | 2008 |