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