]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/listbox.cpp
started macosx compliant implementation
[wxWidgets.git] / src / mac / carbon / listbox.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: listbox.cpp
3 // Purpose: wxListBox
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "listbox.h"
14 #endif
15
16 #include "wx/app.h"
17 #include "wx/listbox.h"
18 #include "wx/settings.h"
19 #include "wx/dynarray.h"
20 #include "wx/log.h"
21
22 #include "wx/utils.h"
23 #ifndef __DARWIN__
24 // #include "extldef.h"
25 #endif
26
27 #if !USE_SHARED_LIBRARY
28 IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl)
29
30 BEGIN_EVENT_TABLE(wxListBox, wxControl)
31 EVT_SIZE( wxListBox::OnSize )
32 END_EVENT_TABLE()
33 #endif
34
35 #include "wx/mac/uma.h"
36
37
38 typedef struct {
39 unsigned short instruction;
40 void (*function)();
41 } ldefRec, *ldefPtr, **ldefHandle;
42
43 extern "C"
44 {
45 static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect *drawRect,
46 Cell cell, short dataOffset, short dataLength,
47 ListHandle listHandle ) ;
48 }
49
50 static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect *drawRect,
51 Cell cell, short dataOffset, short dataLength,
52 ListHandle listHandle )
53 {
54 FontInfo fontInfo;
55 GrafPtr savePort;
56 GrafPtr grafPtr;
57 RgnHandle savedClipRegion;
58 SInt32 savedPenMode;
59 wxListBox* list;
60 GetPort(&savePort);
61 SetPort((**listHandle).port);
62 grafPtr = (**listHandle).port ;
63 // typecast our refCon
64 list = (wxListBox*) GetControlReference( (ControlHandle) GetListRefCon(listHandle) );
65
66 // Calculate the cell rect.
67
68 switch( message ) {
69 case lInitMsg:
70 break;
71
72 case lCloseMsg:
73 break;
74
75 case lDrawMsg:
76 {
77 const wxString text = list->m_stringArray[cell.v] ;
78
79 // Save the current clip region, and set the clip region to the area we are about
80 // to draw.
81
82 savedClipRegion = NewRgn();
83 GetClip( savedClipRegion );
84
85 ClipRect( drawRect );
86 EraseRect( drawRect );
87
88 MoveTo(drawRect->left + 4 , drawRect->top + 10 );
89 ::TextFont( kFontIDMonaco ) ;
90 ::TextSize( 9 );
91 ::TextFace( 0 ) ;
92
93 DrawText(text, 0 , text.Length());
94 // If the cell is hilited, do the hilite now. Paint the cell contents with the
95 // appropriate QuickDraw transform mode.
96
97 if( isSelected ) {
98 savedPenMode = GetPortPenMode( grafPtr );
99 SetPortPenMode( grafPtr, hilitetransfermode );
100 PaintRect( drawRect );
101 SetPortPenMode( grafPtr, savedPenMode );
102 }
103
104 // Restore the saved clip region.
105
106 SetClip( savedClipRegion );
107 DisposeRgn( savedClipRegion );
108 }
109 break;
110 case lHiliteMsg:
111
112 // Hilite or unhilite the cell. Paint the cell contents with the
113 // appropriate QuickDraw transform mode.
114
115 GetPort( &grafPtr );
116 savedPenMode = GetPortPenMode( grafPtr );
117 SetPortPenMode( grafPtr, hilitetransfermode );
118 PaintRect( drawRect );
119 SetPortPenMode( grafPtr, savedPenMode );
120 break;
121 default :
122 break ;
123 }
124 SetPort(savePort);
125 }
126
127 extern "C" void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon) ;
128 const short kwxMacListWithVerticalScrollbar = 128 ;
129
130 // ============================================================================
131 // list box control implementation
132 // ============================================================================
133
134 // Listbox item
135 wxListBox::wxListBox()
136 {
137 m_noItems = 0;
138 m_selected = 0;
139 m_macList = NULL ;
140 }
141
142 static ListDefUPP macListDefUPP = NULL ;
143
144 bool wxListBox::Create(wxWindow *parent, wxWindowID id,
145 const wxPoint& pos,
146 const wxSize& size,
147 int n, const wxString choices[],
148 long style,
149 const wxValidator& validator,
150 const wxString& name)
151 {
152 m_noItems = 0 ; // this will be increased by our append command
153 m_selected = 0;
154
155 Rect bounds ;
156 Str255 title ;
157
158 MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ;
159
160 ListDefSpec listDef;
161 listDef.defType = kListDefUserProcType;
162 if ( macListDefUPP == NULL )
163 {
164 macListDefUPP = NewListDefUPP( wxMacListDefinition );
165 }
166 listDef.u.userProc = macListDefUPP ;
167 #if TARGET_CARBON
168 Size asize;
169
170
171 CreateListBoxControl( parent->MacGetRootWindow(), &bounds, false, 0, 1, false, true,
172 14, 14, false, &listDef, &m_macControl );
173
174 GetControlData(m_macControl, kControlNoPart, kControlListBoxListHandleTag,
175 sizeof(ListHandle), (Ptr) &m_macList, &asize);
176
177 SetControlReference(m_macControl, (long) this);
178 SetControlVisibility(m_macControl, false, false);
179
180 #else
181 long result ;
182
183 m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false ,
184 kwxMacListWithVerticalScrollbar , 0 , 0,
185 kControlListBoxProc , (long) this ) ;
186 ::GetControlData( m_macControl , kControlNoPart , kControlListBoxListHandleTag ,
187 sizeof( ListHandle ) , (char*) &m_macList , &result ) ;
188
189 HLock( (Handle) m_macList ) ;
190 ldefHandle ldef ;
191 ldef = (ldefHandle) NewHandle( sizeof(ldefRec) ) ;
192 if ( (**m_macList).listDefProc != NULL )
193 {
194 (**ldef).instruction = 0x4EF9; /* JMP instruction */
195 (**ldef).function = (void(*)()) listDef.u.userProc;
196 (**m_macList).listDefProc = (Handle) ldef ;
197 }
198
199 Point pt = (**m_macList).cellSize ;
200 pt.v = 14 ;
201 LCellSize( pt , m_macList ) ;
202
203 LAddColumn( 1 , 0 , m_macList ) ;
204 #endif
205 OptionBits options = 0;
206 if ( style & wxLB_MULTIPLE )
207 {
208 options += lNoExtend ;
209 }
210 else if ( style & wxLB_EXTENDED )
211 {
212 options += lExtendDrag ;
213 }
214 else
215 {
216 options = lOnlyOne ;
217 }
218 SetListSelectionFlags(m_macList, options);
219
220 MacPostControlCreate() ;
221
222 for ( int i = 0 ; i < n ; i++ )
223 {
224 Append( choices[i] ) ;
225 }
226
227 LSetDrawingMode( true , m_macList ) ;
228
229 return TRUE;
230 }
231
232 wxListBox::~wxListBox()
233 {
234 Free() ;
235 if ( m_macList )
236 {
237 #if !TARGET_CARBON
238 DisposeHandle( (**m_macList).listDefProc ) ;
239 (**m_macList).listDefProc = NULL ;
240 #endif
241 m_macList = NULL ;
242 }
243 }
244
245 void wxListBox::Free()
246 {
247 #if wxUSE_OWNER_DRAWN
248 if ( m_windowStyle & wxLB_OWNERDRAW )
249 {
250 size_t uiCount = m_aItems.Count();
251 while ( uiCount-- != 0 ) {
252 delete m_aItems[uiCount];
253 }
254
255 m_aItems.Clear();
256 }
257 else
258 #endif // wxUSE_OWNER_DRAWN
259 if ( HasClientObjectData() )
260 {
261 for ( size_t n = 0; n < (size_t)m_noItems; n++ )
262 {
263 delete GetClientObject(n);
264 }
265 }
266 }
267
268 void wxListBox::DoSetSize(int x, int y,
269 int width, int height,
270 int sizeFlags )
271 {
272 wxControl::DoSetSize( x , y , width , height , sizeFlags ) ;
273 #if TARGET_CARBON
274 Rect bounds ;
275 GetControlBounds( m_macControl , &bounds ) ;
276 ControlRef control = GetListVerticalScrollBar( m_macList ) ;
277 if ( control )
278 {
279 Rect scrollbounds ;
280 GetControlBounds( control , &scrollbounds ) ;
281 if( scrollbounds.right != bounds.right + 1 )
282 {
283 UMAMoveControl( control , bounds.right - (scrollbounds.right - scrollbounds.left) + 1 ,
284 scrollbounds.top ) ;
285 }
286 }
287 #endif
288 }
289 void wxListBox::DoSetFirstItem(int N)
290 {
291 MacScrollTo( N ) ;
292 }
293
294 void wxListBox::Delete(int N)
295 {
296 wxCHECK_RET( N >= 0 && N < m_noItems,
297 wxT("invalid index in wxListBox::Delete") );
298
299 #if wxUSE_OWNER_DRAWN
300 delete m_aItems[N];
301 m_aItems.RemoveAt(N);
302 #else // !wxUSE_OWNER_DRAWN
303 if ( HasClientObjectData() )
304 {
305 delete GetClientObject(N);
306 }
307 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
308 m_stringArray.Remove( N ) ;
309 m_dataArray.RemoveAt( N ) ;
310 m_noItems --;
311
312 MacDelete( N ) ;
313 }
314
315 int wxListBox::DoAppend(const wxString& item)
316 {
317 int index = m_noItems ;
318 if( wxApp::s_macDefaultEncodingIsPC )
319 {
320 m_stringArray.Add( wxMacMakeMacStringFromPC( item ) ) ;
321 m_dataArray.Add( NULL );
322 }
323 else {
324 m_stringArray.Add( item ) ;
325 m_dataArray.Add( NULL );
326 }
327 m_noItems ++;
328 DoSetItemClientData( index , NULL ) ;
329 MacAppend( item ) ;
330
331 return index ;
332 }
333
334 void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData)
335 {
336 MacSetRedraw( false ) ;
337 Clear() ;
338 int n = choices.GetCount();
339
340 for( int i = 0 ; i < n ; ++i )
341 {
342 if ( clientData )
343 {
344 #if wxUSE_OWNER_DRAWN
345 wxASSERT_MSG(clientData[i] == NULL,
346 wxT("Can't use client data with owner-drawn listboxes"));
347 #else // !wxUSE_OWNER_DRAWN
348 Append( choices[i] , clientData[i] ) ;
349 #endif
350 }
351 else
352 Append( choices[i] ) ;
353 }
354
355 #if wxUSE_OWNER_DRAWN
356 if ( m_windowStyle & wxLB_OWNERDRAW ) {
357 // first delete old items
358 size_t ui = m_aItems.Count();
359 while ( ui-- != 0 ) {
360 delete m_aItems[ui];
361 }
362 m_aItems.Empty();
363
364 // then create new ones
365 for ( ui = 0; ui < (size_t)m_noItems; ui++ ) {
366 wxOwnerDrawn *pNewItem = CreateItem(ui);
367 pNewItem->SetName(choices[ui]);
368 m_aItems.Add(pNewItem);
369 }
370 }
371 #endif // wxUSE_OWNER_DRAWN
372 MacSetRedraw( true ) ;
373 }
374
375 bool wxListBox::HasMultipleSelection() const
376 {
377 return (m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED);
378 }
379
380 int wxListBox::FindString(const wxString& st) const
381 {
382 wxString s ;
383 if( wxApp::s_macDefaultEncodingIsPC )
384 {
385 s = wxMacMakeMacStringFromPC( st ) ;
386 }
387 else
388 s = st ;
389
390 if ( s.Right(1) == "*" )
391 {
392 wxString search = s.Left( s.Length() - 1 ) ;
393 int len = search.Length() ;
394 Str255 s1 , s2 ;
395
396 #if TARGET_CARBON
397 c2pstrcpy( (StringPtr) s2 , search.c_str() ) ;
398 #else
399 strcpy( (char *) s2 , search.c_str() ) ;
400 c2pstr( (char *) s2 ) ;
401 #endif
402
403 for ( int i = 0 ; i < m_noItems ; ++ i )
404 {
405 #if TARGET_CARBON
406 c2pstrcpy( (StringPtr) s1 , m_stringArray[i].Left( len ).c_str() ) ;
407 #else
408 strcpy( (char *) s1 , m_stringArray[i].Left( len ).c_str() ) ;
409 c2pstr( (char *) s1 ) ;
410 #endif
411 if ( EqualString( s1 , s2 , false , false ) )
412 return i ;
413 }
414 if ( s.Left(1) == "*" && s.Length() > 1 )
415 {
416 s.MakeLower() ;
417 for ( int i = 0 ; i < m_noItems ; ++i )
418 {
419 if ( GetString(i).Lower().Matches(s) )
420 return i ;
421 }
422 }
423
424 }
425 else
426 {
427 Str255 s1 , s2 ;
428
429 #if TARGET_CARBON
430 c2pstrcpy( (StringPtr) s2 , s.c_str() ) ;
431 #else
432 strcpy( (char *) s2 , s.c_str() ) ;
433 c2pstr( (char *) s2 ) ;
434 #endif
435
436 for ( int i = 0 ; i < m_noItems ; ++ i )
437 {
438 #if TARGET_CARBON
439 c2pstrcpy( (StringPtr) s1 , m_stringArray[i].c_str() ) ;
440 #else
441 strcpy( (char *) s1 , m_stringArray[i].c_str() ) ;
442 c2pstr( (char *) s1 ) ;
443 #endif
444 if ( EqualString( s1 , s2 , false , false ) )
445 return i ;
446 }
447 }
448 return -1;
449 }
450
451 void wxListBox::Clear()
452 {
453 Free();
454 m_noItems = 0;
455 m_stringArray.Empty() ;
456 m_dataArray.Empty() ;
457 MacClear() ;
458 }
459
460 void wxListBox::SetSelection(int N, bool select)
461 {
462 wxCHECK_RET( N >= 0 && N < m_noItems,
463 "invalid index in wxListBox::SetSelection" );
464 MacSetSelection( N , select ) ;
465 GetSelections( m_selectionPreImage ) ;
466 }
467
468 bool wxListBox::IsSelected(int N) const
469 {
470 wxCHECK_MSG( N >= 0 && N < m_noItems, FALSE,
471 "invalid index in wxListBox::Selected" );
472
473 return MacIsSelected( N ) ;
474 }
475
476 void *wxListBox::DoGetItemClientData(int N) const
477 {
478 wxCHECK_MSG( N >= 0 && N < m_noItems, NULL,
479 wxT("invalid index in wxListBox::GetClientData"));
480
481 return (void *)m_dataArray[N];
482 }
483
484 wxClientData *wxListBox::DoGetItemClientObject(int N) const
485 {
486 return (wxClientData *) DoGetItemClientData( N ) ;
487 }
488
489 void wxListBox::DoSetItemClientData(int N, void *Client_data)
490 {
491 wxCHECK_RET( N >= 0 && N < m_noItems,
492 "invalid index in wxListBox::SetClientData" );
493
494 #if wxUSE_OWNER_DRAWN
495 if ( m_windowStyle & wxLB_OWNERDRAW )
496 {
497 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
498 // in OnMeasure/OnDraw.
499 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
500 }
501 #endif // wxUSE_OWNER_DRAWN
502 wxASSERT_MSG( m_dataArray.GetCount() >= N , "invalid client_data array" ) ;
503
504 if ( m_dataArray.GetCount() > N )
505 {
506 m_dataArray[N] = (char*) Client_data ;
507 }
508 else
509 {
510 m_dataArray.Add( (char*) Client_data ) ;
511 }
512 }
513
514 void wxListBox::DoSetItemClientObject(int n, wxClientData* clientData)
515 {
516 DoSetItemClientData(n, clientData);
517 }
518
519 // Return number of selections and an array of selected integers
520 int wxListBox::GetSelections(wxArrayInt& aSelections) const
521 {
522 return MacGetSelections( aSelections ) ;
523 }
524
525 // Get single selection, for single choice list items
526 int wxListBox::GetSelection() const
527 {
528 return MacGetSelection() ;
529 }
530
531 // Find string for position
532 wxString wxListBox::GetString(int N) const
533 {
534 if( wxApp::s_macDefaultEncodingIsPC )
535 {
536 return wxMacMakePCStringFromMac( m_stringArray[N] ) ;
537 }
538 else
539 return m_stringArray[N] ;
540 }
541
542 void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
543 {
544 wxCHECK_RET( pos >= 0 && pos <= m_noItems,
545 wxT("invalid index in wxListBox::InsertItems") );
546
547 int nItems = items.GetCount();
548
549 for ( int i = 0 ; i < nItems ; i++ )
550 {
551 m_stringArray.Insert( items[i] , pos + i ) ;
552 m_dataArray.Insert( NULL , pos + i ) ;
553 MacInsert( pos + i , items[i] ) ;
554 }
555
556 m_noItems += nItems;
557 }
558
559 void wxListBox::SetString(int N, const wxString& s)
560 {
561 wxString str ;
562 if( wxApp::s_macDefaultEncodingIsPC )
563 {
564 str = wxMacMakeMacStringFromPC( s ) ;
565 }
566 else
567 str = s ;
568 m_stringArray[N] = str ;
569 MacSet( N , s ) ;
570 }
571
572 wxSize wxListBox::DoGetBestSize() const
573 {
574 return wxSize(100, 100);
575 }
576
577 int wxListBox::GetCount() const
578 {
579 return m_noItems;
580 }
581
582 void wxListBox::SetupColours()
583 {
584 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW));
585 SetForegroundColour(GetParent()->GetForegroundColour());
586 }
587
588 void wxListBox::Refresh(bool eraseBack, const wxRect *rect)
589 {
590 // Set up port
591 WindowRef rootwindow = MacGetRootWindow() ;
592 wxWindow* wxrootwindow = wxFindWinFromMacWindow( rootwindow ) ;
593 wxMacDrawingHelper focus( wxrootwindow );
594
595 UMADrawControl(m_macControl);
596 }
597
598 #if wxUSE_OWNER_DRAWN
599
600 class wxListBoxItem : public wxOwnerDrawn
601 {
602 public:
603 wxListBoxItem(const wxString& str = "");
604 };
605
606 wxListBoxItem::wxListBoxItem(const wxString& str) : wxOwnerDrawn(str, FALSE)
607 {
608 // no bitmaps/checkmarks
609 SetMarginWidth(0);
610 }
611
612 wxOwnerDrawn *wxListBox::CreateItem(size_t n)
613 {
614 return new wxListBoxItem();
615 }
616
617 #endif //USE_OWNER_DRAWN
618
619 // ============================================================================
620 // list box control implementation
621 // ============================================================================
622
623 void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
624 {
625 wxListBox* list;
626 // typecast our refCon
627 list = (wxListBox*)refCon;
628
629 MoveTo(cellRect->left + 4 , cellRect->top + 10 );
630 const wxString text = list->m_stringArray[lCell.v] ;
631 ::TextFont( kFontIDMonaco ) ;
632 ::TextSize( 9 );
633 ::TextFace( 0 ) ;
634 DrawText(text, 0 , text.Length());
635
636 }
637
638 void wxListBox::MacDelete( int N )
639 {
640 LDelRow( 1 , N , m_macList) ;
641 Refresh();
642 }
643
644 void wxListBox::MacInsert( int n , const char * text)
645 {
646 Cell cell = { 0 , 0 } ;
647 cell.v = n ;
648 LAddRow( 1 , cell.v , m_macList ) ;
649 // LSetCell(text, strlen(text), cell, m_macList);
650 Refresh();
651 }
652
653 void wxListBox::MacAppend( const char * text)
654 {
655 Cell cell = { 0 , 0 } ;
656 cell.v = (**m_macList).dataBounds.bottom ;
657 LAddRow( 1 , cell.v , m_macList ) ;
658 // LSetCell(text, strlen(text), cell, m_macList);
659 Refresh();
660 }
661
662 void wxListBox::MacClear()
663 {
664 LDelRow( (**m_macList).dataBounds.bottom , 0 , m_macList ) ;
665 Refresh();
666 }
667
668 void wxListBox::MacSetSelection( int n , bool select )
669 {
670 Cell cell = { 0 , 0 } ;
671 if ( ! (m_windowStyle & wxLB_MULTIPLE) )
672 {
673 if ( LGetSelect( true , &cell , m_macList ) )
674 {
675 LSetSelect( false , cell , m_macList ) ;
676 }
677 }
678
679 cell.v = n ;
680 LSetSelect( select , cell , m_macList ) ;
681 LAutoScroll( m_macList ) ;
682 Refresh();
683 }
684
685 bool wxListBox::MacIsSelected( int n ) const
686 {
687 Cell cell = { 0 , 0 } ;
688 cell.v = n ;
689 return LGetSelect( false , &cell , m_macList ) ;
690 }
691
692 void wxListBox::MacDestroy()
693 {
694 // DisposeExtLDEFInfo( m_macList ) ;
695 }
696
697 int wxListBox::MacGetSelection() const
698 {
699 Cell cell = { 0 , 0 } ;
700 if ( LGetSelect( true , &cell , m_macList ) )
701 return cell.v ;
702 else
703 return -1 ;
704 }
705
706 int wxListBox::MacGetSelections( wxArrayInt& aSelections ) const
707 {
708 int no_sel = 0 ;
709
710 aSelections.Empty();
711
712 Cell cell = { 0 , 0 } ;
713 cell.v = 0 ;
714
715 while ( LGetSelect( true , &cell , m_macList ) )
716 {
717 aSelections.Add( cell.v ) ;
718 no_sel++ ;
719 cell.v++ ;
720 }
721 return no_sel ;
722 }
723
724 void wxListBox::MacSet( int n , const char * text )
725 {
726 // our implementation does not store anything in the list
727 // so we just have to redraw
728 Cell cell = { 0 , 0 } ;
729 cell.v = n ;
730 // LSetCell(text, strlen(text), cell, m_macList);
731 Refresh();
732 }
733
734 void wxListBox::MacScrollTo( int n )
735 {
736 // TODO implement scrolling
737 }
738
739 void wxListBox::OnSize( const wxSizeEvent &event)
740 {
741 Point pt;
742
743 #if TARGET_CARBON
744 GetListCellSize(m_macList, &pt);
745 #else
746 pt = (**m_macList).cellSize ;
747 #endif
748 pt.h = m_width - 15 ;
749 LCellSize( pt , m_macList ) ;
750 }
751
752 void wxListBox::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
753 {
754 Boolean wasDoubleClick = false ;
755 long result ;
756
757 ::GetControlData( m_macControl , kControlNoPart , kControlListBoxDoubleClickTag , sizeof( wasDoubleClick ) , (char*) &wasDoubleClick , &result ) ;
758 if ( !wasDoubleClick )
759 {
760 MacDoClick() ;
761 }
762 else
763 {
764 MacDoDoubleClick() ;
765 }
766 }
767
768 void wxListBox::MacSetRedraw( bool doDraw )
769 {
770 LSetDrawingMode( doDraw , m_macList ) ;
771
772 }
773
774 void wxListBox::MacDoClick()
775 {
776 wxArrayInt aSelections;
777 int n, count = GetSelections(aSelections);
778
779 if ( count == m_selectionPreImage.GetCount() )
780 {
781 bool hasChanged = false ;
782 for ( int i = 0 ; i < count ; ++i )
783 {
784 if ( aSelections[i] != m_selectionPreImage[i] )
785 {
786 hasChanged = true ;
787 break ;
788 }
789 }
790 if ( !hasChanged )
791 {
792 return ;
793 }
794 }
795
796 m_selectionPreImage = aSelections;
797
798 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId);
799 event.SetEventObject( this );
800
801 if ( count > 0 )
802 {
803 n = aSelections[0];
804 if ( HasClientObjectData() )
805 event.SetClientObject( GetClientObject(n) );
806 else if ( HasClientUntypedData() )
807 event.SetClientData( GetClientData(n) );
808 event.SetString( GetString(n) );
809 }
810 else
811 {
812 n = -1;
813 }
814
815 event.m_commandInt = n;
816
817 GetEventHandler()->ProcessEvent(event);
818 }
819
820 void wxListBox::MacDoDoubleClick()
821 {
822 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, m_windowId);
823 event.SetEventObject( this );
824 GetEventHandler()->ProcessEvent(event) ;
825 }