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