]> git.saurik.com Git - wxWidgets.git/blame - src/generic/vlbox.cpp
missing commit
[wxWidgets.git] / src / generic / vlbox.cpp
CommitLineData
e0c6027b 1///////////////////////////////////////////////////////////////////////////////
e19ac18a 2// Name: src/generic/vlbox.cpp
e0c6027b
VZ
3// Purpose: implementation of wxVListBox
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 31.05.03
7// RCS-ID: $Id$
8// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
526954c5 9// Licence: wxWindows licence
e0c6027b
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
179e085f
RN
27#if wxUSE_LISTBOX
28
2a673eb1
WS
29#include "wx/vlbox.h"
30
e0c6027b
VZ
31#ifndef WX_PRECOMP
32 #include "wx/settings.h"
bb178b29 33 #include "wx/dcclient.h"
2a673eb1 34 #include "wx/listbox.h"
e0c6027b
VZ
35#endif //WX_PRECOMP
36
0975a8a0 37#include "wx/dcbuffer.h"
be465555 38#include "wx/selstore.h"
04125489 39#include "wx/renderer.h"
e0c6027b
VZ
40
41// ----------------------------------------------------------------------------
42// event tables
43// ----------------------------------------------------------------------------
44
45BEGIN_EVENT_TABLE(wxVListBox, wxVScrolledWindow)
46 EVT_PAINT(wxVListBox::OnPaint)
47
48 EVT_KEY_DOWN(wxVListBox::OnKeyDown)
49 EVT_LEFT_DOWN(wxVListBox::OnLeftDown)
50 EVT_LEFT_DCLICK(wxVListBox::OnLeftDClick)
04125489
VZ
51
52 EVT_SET_FOCUS(wxVListBox::OnSetOrKillFocus)
53 EVT_KILL_FOCUS(wxVListBox::OnSetOrKillFocus)
858ad670
JS
54
55 EVT_SIZE(wxVListBox::OnSize)
e0c6027b
VZ
56END_EVENT_TABLE()
57
58// ============================================================================
59// implementation
60// ============================================================================
61
0c8392ca 62IMPLEMENT_ABSTRACT_CLASS(wxVListBox, wxVScrolledWindow)
a805142d 63const char wxVListBoxNameStr[] = "wxVListBox";
0c8392ca 64
e0c6027b
VZ
65// ----------------------------------------------------------------------------
66// wxVListBox creation
67// ----------------------------------------------------------------------------
68
69void wxVListBox::Init()
70{
970b97a2
VZ
71 m_current =
72 m_anchor = wxNOT_FOUND;
be465555 73 m_selStore = NULL;
e0c6027b
VZ
74}
75
76bool wxVListBox::Create(wxWindow *parent,
77 wxWindowID id,
78 const wxPoint& pos,
79 const wxSize& size,
e0c6027b
VZ
80 long style,
81 const wxString& name)
82{
a047aff2 83#ifdef __WXMSW__
9543d01c
VZ
84 if ( (style & wxBORDER_MASK) == wxDEFAULT )
85 style |= wxBORDER_THEME;
a047aff2
JS
86#endif
87
fef7400f 88 style |= wxWANTS_CHARS | wxFULL_REPAINT_ON_RESIZE;
e0c6027b
VZ
89 if ( !wxVScrolledWindow::Create(parent, id, pos, size, style, name) )
90 return false;
91
be465555
VZ
92 if ( style & wxLB_MULTIPLE )
93 m_selStore = new wxSelectionStore;
e0c6027b 94
dc596072
RD
95 // make sure the native widget has the right colour since we do
96 // transparent drawing by default
97 SetBackgroundColour(GetBackgroundColour());
04125489
VZ
98
99 // leave m_colBgSel in an invalid state: it means for OnDrawBackground()
100 // to use wxRendererNative instead of painting selection bg ourselves
101 m_colBgSel = wxNullColour;
9a9b4940 102
0975a8a0
JS
103 // flicker-free drawing requires this
104 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
105
e0c6027b
VZ
106 return true;
107}
108
be465555
VZ
109wxVListBox::~wxVListBox()
110{
111 delete m_selStore;
112}
113
114void wxVListBox::SetItemCount(size_t count)
115{
9543d01c
VZ
116 // don't leave the current index invalid
117 if ( m_current != wxNOT_FOUND && (size_t)m_current >= count )
118 m_current = count - 1; // also ok when count == 0 as wxNOT_FOUND == -1
119
be465555
VZ
120 if ( m_selStore )
121 {
122 // tell the selection store that our number of items has changed
123 m_selStore->SetItemCount(count);
124 }
125
f18eaf26 126 SetRowCount(count);
be465555
VZ
127}
128
e0c6027b
VZ
129// ----------------------------------------------------------------------------
130// selection handling
131// ----------------------------------------------------------------------------
132
be465555
VZ
133bool wxVListBox::IsSelected(size_t line) const
134{
135 return m_selStore ? m_selStore->IsSelected(line) : (int)line == m_current;
136}
137
138bool wxVListBox::Select(size_t item, bool select)
139{
140 wxCHECK_MSG( m_selStore, false,
9a83f860 141 wxT("Select() may only be used with multiselection listbox") );
be465555
VZ
142
143 wxCHECK_MSG( item < GetItemCount(), false,
9a83f860 144 wxT("Select(): invalid item index") );
be465555
VZ
145
146 bool changed = m_selStore->SelectItem(item, select);
147 if ( changed )
148 {
149 // selection really changed
e02c72fa 150 RefreshRow(item);
be465555
VZ
151 }
152
153 DoSetCurrent(item);
154
155 return changed;
156}
157
158bool wxVListBox::SelectRange(size_t from, size_t to)
e0c6027b 159{
be465555 160 wxCHECK_MSG( m_selStore, false,
9a83f860 161 wxT("SelectRange() may only be used with multiselection listbox") );
be465555
VZ
162
163 // make sure items are in correct order
164 if ( from > to )
165 {
166 size_t tmp = from;
167 from = to;
168 to = tmp;
169 }
170
171 wxCHECK_MSG( to < GetItemCount(), false,
9a83f860 172 wxT("SelectRange(): invalid item index") );
be465555
VZ
173
174 wxArrayInt changed;
175 if ( !m_selStore->SelectRange(from, to, true, &changed) )
176 {
177 // too many items have changed, we didn't record them in changed array
178 // so we have no choice but to refresh everything between from and to
e02c72fa 179 RefreshRows(from, to);
be465555
VZ
180 }
181 else // we've got the indices of the changed items
182 {
183 const size_t count = changed.GetCount();
184 if ( !count )
185 {
186 // nothing changed
187 return false;
188 }
189
190 // refresh just the lines which have really changed
191 for ( size_t n = 0; n < count; n++ )
192 {
e02c72fa 193 RefreshRow(changed[n]);
be465555
VZ
194 }
195 }
196
197 // something changed
198 return true;
199}
200
201bool wxVListBox::DoSelectAll(bool select)
202{
203 wxCHECK_MSG( m_selStore, false,
9a83f860 204 wxT("SelectAll may only be used with multiselection listbox") );
be465555
VZ
205
206 size_t count = GetItemCount();
207 if ( count )
208 {
209 wxArrayInt changed;
210 if ( !m_selStore->SelectRange(0, count - 1, select) ||
211 !changed.IsEmpty() )
212 {
213 Refresh();
214
215 // something changed
216 return true;
217 }
218 }
219
220 return false;
221}
222
223bool wxVListBox::DoSetCurrent(int current)
224{
6c9210a7
VZ
225 wxASSERT_MSG( current == wxNOT_FOUND ||
226 (current >= 0 && (size_t)current < GetItemCount()),
9a83f860 227 wxT("wxVListBox::DoSetCurrent(): invalid item index") );
6c9210a7 228
be465555 229 if ( current == m_current )
e0c6027b
VZ
230 {
231 // nothing to do
be465555 232 return false;
e0c6027b
VZ
233 }
234
be465555 235 if ( m_current != wxNOT_FOUND )
e02c72fa 236 RefreshRow(m_current);
e0c6027b 237
be465555 238 m_current = current;
e0c6027b 239
be465555 240 if ( m_current != wxNOT_FOUND )
e0c6027b
VZ
241 {
242 // if the line is not visible at all, we scroll it into view but we
243 // don't need to refresh it -- it will be redrawn anyhow
be465555 244 if ( !IsVisible(m_current) )
e0c6027b 245 {
e02c72fa 246 ScrollToRow(m_current);
e0c6027b
VZ
247 }
248 else // line is at least partly visible
249 {
250 // it is, indeed, only partly visible, so scroll it into view to
251 // make it entirely visible
7d0cf3f9
VZ
252 // BUT scrolling down when m_current is first visible makes it
253 // completely hidden, so that is even worse
e02c72fa 254 while ( (size_t)m_current + 1 == GetVisibleRowsEnd() &&
7d0cf3f9 255 (size_t)m_current != GetVisibleRowsBegin() &&
e02c72fa 256 ScrollToRow(GetVisibleBegin() + 1) ) ;
e0c6027b
VZ
257
258 // but in any case refresh it as even if it was only partly visible
259 // before we need to redraw it entirely as its background changed
e02c72fa 260 RefreshRow(m_current);
e0c6027b 261 }
be465555 262 }
e0c6027b 263
be465555
VZ
264 return true;
265}
e0c6027b 266
538483d8
FM
267void wxVListBox::InitEvent(wxCommandEvent& event, int n)
268{
269 event.SetEventObject(this);
270 event.SetInt(n);
271}
272
be465555
VZ
273void wxVListBox::SendSelectedEvent()
274{
275 wxASSERT_MSG( m_current != wxNOT_FOUND,
9a83f860 276 wxT("SendSelectedEvent() shouldn't be called") );
be465555 277
ce7fe42e 278 wxCommandEvent event(wxEVT_LISTBOX, GetId());
538483d8 279 InitEvent(event, m_current);
be465555
VZ
280 (void)GetEventHandler()->ProcessEvent(event);
281}
282
283void wxVListBox::SetSelection(int selection)
284{
6c9210a7
VZ
285 wxCHECK_RET( selection == wxNOT_FOUND ||
286 (selection >= 0 && (size_t)selection < GetItemCount()),
9a83f860 287 wxT("wxVListBox::SetSelection(): invalid item index") );
6c9210a7 288
de5d3a20
VZ
289 if ( HasMultipleSelection() )
290 {
ad679137
VZ
291 if (selection != wxNOT_FOUND)
292 Select(selection);
293 else
294 DeselectAll();
de5d3a20
VZ
295 m_anchor = selection;
296 }
be465555
VZ
297
298 DoSetCurrent(selection);
299}
300
301size_t wxVListBox::GetSelectedCount() const
302{
303 return m_selStore ? m_selStore->GetSelectedCount()
304 : m_current == wxNOT_FOUND ? 0 : 1;
305}
306
307int wxVListBox::GetFirstSelected(unsigned long& cookie) const
308{
309 cookie = 0;
310
311 return GetNextSelected(cookie);
312}
313
314int wxVListBox::GetNextSelected(unsigned long& cookie) const
315{
316 wxCHECK_MSG( m_selStore, wxNOT_FOUND,
9a83f860 317 wxT("GetFirst/NextSelected() may only be used with multiselection listboxes") );
be465555
VZ
318
319 while ( cookie < GetItemCount() )
320 {
321 if ( IsSelected(cookie++) )
322 return cookie - 1;
e0c6027b 323 }
be465555
VZ
324
325 return wxNOT_FOUND;
e0c6027b
VZ
326}
327
04125489
VZ
328void wxVListBox::RefreshSelected()
329{
330 // only refresh those items which are currently visible and selected:
331 for ( size_t n = GetVisibleBegin(), end = GetVisibleEnd(); n < end; n++ )
332 {
333 if ( IsSelected(n) )
f18eaf26 334 RefreshRow(n);
04125489
VZ
335 }
336}
337
293b15f7
VZ
338wxRect wxVListBox::GetItemRect(size_t n) const
339{
340 wxRect itemrect;
341
342 // check that this item is visible
343 const size_t lineMax = GetVisibleEnd();
344 if ( n >= lineMax )
345 return itemrect;
346 size_t line = GetVisibleBegin();
347 if ( n < line )
348 return itemrect;
349
350 while ( line <= n )
351 {
352 itemrect.y += itemrect.height;
353 itemrect.height = OnGetRowHeight(line);
354
355 line++;
356 }
357
358 itemrect.width = GetClientSize().x;
359
360 return itemrect;
361}
362
e0c6027b 363// ----------------------------------------------------------------------------
9a9b4940 364// wxVListBox appearance parameters
e0c6027b
VZ
365// ----------------------------------------------------------------------------
366
367void wxVListBox::SetMargins(const wxPoint& pt)
368{
369 if ( pt != m_ptMargins )
370 {
371 m_ptMargins = pt;
372
373 Refresh();
374 }
375}
376
9a9b4940
VZ
377void wxVListBox::SetSelectionBackground(const wxColour& col)
378{
379 m_colBgSel = col;
380}
381
382// ----------------------------------------------------------------------------
383// wxVListBox painting
384// ----------------------------------------------------------------------------
385
e02c72fa 386wxCoord wxVListBox::OnGetRowHeight(size_t line) const
e0c6027b
VZ
387{
388 return OnMeasureItem(line) + 2*m_ptMargins.y;
389}
390
391void wxVListBox::OnDrawSeparator(wxDC& WXUNUSED(dc),
392 wxRect& WXUNUSED(rect),
393 size_t WXUNUSED(n)) const
394{
395}
396
c848185a
VZ
397bool
398wxVListBox::DoDrawSolidBackground(const wxColour& col,
399 wxDC& dc,
400 const wxRect& rect,
401 size_t n) const
27d0dcd0 402{
c848185a
VZ
403 if ( !col.IsOk() )
404 return false;
405
406 // we need to render selected and current items differently
407 const bool isSelected = IsSelected(n),
408 isCurrent = IsCurrent(n);
409 if ( isSelected || isCurrent )
27d0dcd0 410 {
c848185a 411 if ( isSelected )
27d0dcd0 412 {
04ee05f9 413 dc.SetBrush(wxBrush(col, wxBRUSHSTYLE_SOLID));
27d0dcd0 414 }
c848185a
VZ
415 else // !selected
416 {
417 dc.SetBrush(*wxTRANSPARENT_BRUSH);
418 }
419 dc.SetPen(*(isCurrent ? wxBLACK_PEN : wxTRANSPARENT_PEN));
420 dc.DrawRectangle(rect);
04125489 421 }
c848185a
VZ
422 //else: do nothing for the normal items
423
424 return true;
425}
426
427void wxVListBox::OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const
428{
429 // use wxRendererNative for more native look unless we use custom bg colour
430 if ( !DoDrawSolidBackground(m_colBgSel, dc, rect, n) )
04125489
VZ
431 {
432 int flags = 0;
433 if ( IsSelected(n) )
434 flags |= wxCONTROL_SELECTED;
435 if ( IsCurrent(n) )
436 flags |= wxCONTROL_CURRENT;
5c33522f 437 if ( wxWindow::FindFocus() == const_cast<wxVListBox*>(this) )
04125489
VZ
438 flags |= wxCONTROL_FOCUSED;
439
440 wxRendererNative::Get().DrawItemSelectionRect(
5c33522f 441 const_cast<wxVListBox *>(this), dc, rect, flags);
27d0dcd0 442 }
27d0dcd0
VZ
443}
444
445void wxVListBox::OnPaint(wxPaintEvent& WXUNUSED(event))
e0c6027b 446{
0975a8a0
JS
447 wxSize clientSize = GetClientSize();
448
2e992e06 449 wxAutoBufferedPaintDC dc(this);
e0c6027b
VZ
450
451 // the update rectangle
452 wxRect rectUpdate = GetUpdateClientRect();
453
959b1a33
VZ
454 // fill it with background colour
455 dc.SetBackground(GetBackgroundColour());
0975a8a0
JS
456 dc.Clear();
457
e0c6027b 458 // the bounding rectangle of the current line
e02c72fa
VZ
459 wxRect rectRow;
460 rectRow.width = clientSize.x;
e0c6027b
VZ
461
462 // iterate over all visible lines
b1b408af 463 const size_t lineMax = GetVisibleEnd();
e02c72fa 464 for ( size_t line = GetVisibleBegin(); line < lineMax; line++ )
e0c6027b 465 {
e02c72fa 466 const wxCoord hRow = OnGetRowHeight(line);
e0c6027b 467
e02c72fa 468 rectRow.height = hRow;
e0c6027b
VZ
469
470 // and draw the ones which intersect the update rect
e02c72fa 471 if ( rectRow.Intersects(rectUpdate) )
e0c6027b
VZ
472 {
473 // don't allow drawing outside of the lines rectangle
e02c72fa 474 wxDCClipper clip(dc, rectRow);
e0c6027b 475
e02c72fa 476 wxRect rect = rectRow;
27d0dcd0
VZ
477 OnDrawBackground(dc, rect, line);
478
e0c6027b
VZ
479 OnDrawSeparator(dc, rect, line);
480
481 rect.Deflate(m_ptMargins.x, m_ptMargins.y);
482 OnDrawItem(dc, rect, line);
483 }
484 else // no intersection
485 {
e02c72fa 486 if ( rectRow.GetTop() > rectUpdate.GetBottom() )
e0c6027b
VZ
487 {
488 // we are already below the update rect, no need to continue
489 // further
490 break;
491 }
492 //else: the next line may intersect the update rect
493 }
494
e02c72fa 495 rectRow.y += hRow;
e0c6027b
VZ
496 }
497}
498
04125489
VZ
499void wxVListBox::OnSetOrKillFocus(wxFocusEvent& WXUNUSED(event))
500{
501 // we need to repaint the selection when we get the focus since
502 // wxRendererNative in general draws the focused selection differently
503 // from the unfocused selection (see OnDrawItem):
504 RefreshSelected();
505}
506
858ad670
JS
507void wxVListBox::OnSize(wxSizeEvent& event)
508{
509 UpdateScrollbar();
510 event.Skip();
511}
04125489 512
be465555
VZ
513// ============================================================================
514// wxVListBox keyboard/mouse handling
515// ============================================================================
516
970b97a2 517void wxVListBox::DoHandleItemClick(int item, int flags)
be465555
VZ
518{
519 // has anything worth telling the client code about happened?
520 bool notify = false;
521
522 if ( HasMultipleSelection() )
523 {
524 // select the iteem clicked?
525 bool select = true;
526
527 // NB: the keyboard interface we implement here corresponds to
528 // wxLB_EXTENDED rather than wxLB_MULTIPLE but this one makes more
529 // sense IMHO
970b97a2 530 if ( flags & ItemClick_Shift )
be465555
VZ
531 {
532 if ( m_current != wxNOT_FOUND )
533 {
970b97a2
VZ
534 if ( m_anchor == wxNOT_FOUND )
535 m_anchor = m_current;
536
be465555
VZ
537 select = false;
538
970b97a2
VZ
539 // only the range from the selection anchor to new m_current
540 // must be selected
be465555
VZ
541 if ( DeselectAll() )
542 notify = true;
543
970b97a2 544 if ( SelectRange(m_anchor, item) )
be465555
VZ
545 notify = true;
546 }
547 //else: treat it as ordinary click/keypress
548 }
970b97a2 549 else // Shift not pressed
be465555 550 {
970b97a2 551 m_anchor = item;
be465555 552
970b97a2
VZ
553 if ( flags & ItemClick_Ctrl )
554 {
555 select = false;
be465555 556
970b97a2
VZ
557 if ( !(flags & ItemClick_Kbd) )
558 {
559 Toggle(item);
560
561 // the status of the item has definitely changed
562 notify = true;
563 }
564 //else: Ctrl-arrow pressed, don't change selection
565 }
566 //else: behave as in single selection case
be465555 567 }
be465555
VZ
568
569 if ( select )
570 {
571 // make the clicked item the only selection
572 if ( DeselectAll() )
573 notify = true;
574
575 if ( Select(item) )
576 notify = true;
577 }
578 }
579
580 // in any case the item should become the current one
581 if ( DoSetCurrent(item) )
582 {
583 if ( !HasMultipleSelection() )
584 {
585 // this has also changed the selection for single selection case
586 notify = true;
587 }
588 }
589
590 if ( notify )
591 {
592 // notify the user about the selection change
593 SendSelectedEvent();
594 }
595 //else: nothing changed at all
596}
597
e0c6027b 598// ----------------------------------------------------------------------------
be465555 599// keyboard handling
e0c6027b
VZ
600// ----------------------------------------------------------------------------
601
602void wxVListBox::OnKeyDown(wxKeyEvent& event)
603{
970b97a2
VZ
604 // flags for DoHandleItemClick()
605 int flags = ItemClick_Kbd;
606
999836aa 607 int current;
e0c6027b
VZ
608 switch ( event.GetKeyCode() )
609 {
610 case WXK_HOME:
293987e8 611 case WXK_NUMPAD_HOME:
be465555 612 current = 0;
e0c6027b
VZ
613 break;
614
615 case WXK_END:
293987e8 616 case WXK_NUMPAD_END:
e02c72fa 617 current = GetRowCount() - 1;
e0c6027b
VZ
618 break;
619
620 case WXK_DOWN:
293987e8 621 case WXK_NUMPAD_DOWN:
e02c72fa 622 if ( m_current == (int)GetRowCount() - 1 )
e0c6027b
VZ
623 return;
624
be465555 625 current = m_current + 1;
e0c6027b
VZ
626 break;
627
628 case WXK_UP:
293987e8 629 case WXK_NUMPAD_UP:
be465555 630 if ( m_current == wxNOT_FOUND )
e02c72fa 631 current = GetRowCount() - 1;
be465555
VZ
632 else if ( m_current != 0 )
633 current = m_current - 1;
634 else // m_current == 0
e0c6027b
VZ
635 return;
636 break;
637
638 case WXK_PAGEDOWN:
293987e8 639 case WXK_NUMPAD_PAGEDOWN:
e0c6027b 640 PageDown();
e02c72fa 641 current = GetVisibleBegin();
e0c6027b
VZ
642 break;
643
644 case WXK_PAGEUP:
293987e8 645 case WXK_NUMPAD_PAGEUP:
e02c72fa 646 if ( m_current == (int)GetVisibleBegin() )
e0c6027b
VZ
647 {
648 PageUp();
649 }
650
e02c72fa 651 current = GetVisibleBegin();
e0c6027b
VZ
652 break;
653
970b97a2
VZ
654 case WXK_SPACE:
655 // hack: pressing space should work like a mouse click rather than
656 // like a keyboard arrow press, so trick DoHandleItemClick() in
657 // thinking we were clicked
658 flags &= ~ItemClick_Kbd;
659 current = m_current;
660 break;
661
80c700cb
RD
662#ifdef __WXMSW__
663 case WXK_TAB:
664 // Since we are using wxWANTS_CHARS we need to send navigation
665 // events for the tabs on MSW
f029f1d1 666 HandleAsNavigationKey(event);
80c700cb
RD
667 // fall through to default
668#endif
e0c6027b
VZ
669 default:
670 event.Skip();
999836aa 671 current = 0; // just to silent the stupid compiler warnings
8703bc01 672 wxUnusedVar(current);
e0c6027b
VZ
673 return;
674 }
675
970b97a2
VZ
676 if ( event.ShiftDown() )
677 flags |= ItemClick_Shift;
678 if ( event.ControlDown() )
679 flags |= ItemClick_Ctrl;
680
681 DoHandleItemClick(current, flags);
e0c6027b
VZ
682}
683
684// ----------------------------------------------------------------------------
685// wxVListBox mouse handling
686// ----------------------------------------------------------------------------
687
688void wxVListBox::OnLeftDown(wxMouseEvent& event)
689{
c7778877 690 SetFocus();
4e115ed2 691
10368bff 692 int item = VirtualHitTest(event.GetPosition().y);
e0c6027b 693
6c9210a7
VZ
694 if ( item != wxNOT_FOUND )
695 {
970b97a2
VZ
696 int flags = 0;
697 if ( event.ShiftDown() )
698 flags |= ItemClick_Shift;
699
6c9210a7
VZ
700 // under Mac Apple-click is used in the same way as Ctrl-click
701 // elsewhere
be465555 702#ifdef __WXMAC__
970b97a2 703 if ( event.MetaDown() )
be465555 704#else
970b97a2 705 if ( event.ControlDown() )
be465555 706#endif
970b97a2
VZ
707 flags |= ItemClick_Ctrl;
708
709 DoHandleItemClick(item, flags);
6c9210a7 710 }
e0c6027b
VZ
711}
712
4e115ed2 713void wxVListBox::OnLeftDClick(wxMouseEvent& eventMouse)
e0c6027b 714{
10368bff 715 int item = VirtualHitTest(eventMouse.GetPosition().y);
be465555 716 if ( item != wxNOT_FOUND )
e0c6027b 717 {
e0c6027b 718
0975a8a0
JS
719 // if item double-clicked was not yet selected, then treat
720 // this event as a left-click instead
721 if ( item == m_current )
722 {
ce7fe42e 723 wxCommandEvent event(wxEVT_LISTBOX_DCLICK, GetId());
538483d8 724 InitEvent(event, item);
0975a8a0
JS
725 (void)GetEventHandler()->ProcessEvent(event);
726 }
727 else
728 {
729 OnLeftDown(eventMouse);
730 }
e19ac18a 731
e0c6027b
VZ
732 }
733}
734
dc596072
RD
735
736// ----------------------------------------------------------------------------
737// use the same default attributes as wxListBox
738// ----------------------------------------------------------------------------
739
dc596072
RD
740//static
741wxVisualAttributes
742wxVListBox::GetClassDefaultAttributes(wxWindowVariant variant)
743{
744 return wxListBox::GetClassDefaultAttributes(variant);
745}
179e085f 746
8b939bc0 747#endif