]> git.saurik.com Git - wxWidgets.git/blob - src/mac/listbox.cpp
removing dependancy on mac headers from public wx headers (eventually adding wx/mac...
[wxWidgets.git] / src / mac / 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/toplevel.h"
20 #include "wx/dynarray.h"
21 #include "wx/log.h"
22
23 #include "wx/utils.h"
24
25 #if !USE_SHARED_LIBRARY
26 IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl)
27
28 BEGIN_EVENT_TABLE(wxListBox, wxControl)
29 EVT_SIZE( wxListBox::OnSize )
30 END_EVENT_TABLE()
31 #endif
32
33 #include "wx/mac/uma.h"
34
35
36 typedef struct {
37 unsigned short instruction;
38 void (*function)();
39 } ldefRec, *ldefPtr, **ldefHandle;
40
41 extern "C"
42 {
43 static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect *drawRect,
44 Cell cell, short dataOffset, short dataLength,
45 ListHandle listHandle ) ;
46 }
47
48 static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect *drawRect,
49 Cell cell, short dataOffset, short dataLength,
50 ListHandle listHandle )
51 {
52 FontInfo fontInfo;
53 GrafPtr savePort;
54 GrafPtr grafPtr;
55 RgnHandle savedClipRegion;
56 SInt32 savedPenMode;
57 wxListBox* list;
58 GetPort(&savePort);
59 SetPort((**listHandle).port);
60 grafPtr = (**listHandle).port ;
61 // typecast our refCon
62 list = (wxListBox*) GetControlReference( (ControlHandle) GetListRefCon(listHandle) );
63
64 // Calculate the cell rect.
65
66 switch( message ) {
67 case lInitMsg:
68 break;
69
70 case lCloseMsg:
71 break;
72
73 case lDrawMsg:
74 {
75 const wxString text = list->m_stringArray[cell.v] ;
76
77 // Save the current clip region, and set the clip region to the area we are about
78 // to draw.
79
80 savedClipRegion = NewRgn();
81 GetClip( savedClipRegion );
82
83 ClipRect( drawRect );
84 EraseRect( drawRect );
85
86 MoveTo(drawRect->left + 4 , drawRect->top + 10 );
87 ::TextFont( kFontIDMonaco ) ;
88 ::TextSize( 9 );
89 ::TextFace( 0 ) ;
90
91 DrawText(text, 0 , text.Length());
92 // If the cell is hilited, do the hilite now. Paint the cell contents with the
93 // appropriate QuickDraw transform mode.
94
95 if( isSelected ) {
96 savedPenMode = GetPortPenMode( (CGrafPtr) grafPtr );
97 SetPortPenMode( (CGrafPtr)grafPtr, hilitetransfermode );
98 PaintRect( drawRect );
99 SetPortPenMode( (CGrafPtr)grafPtr, savedPenMode );
100 }
101
102 // Restore the saved clip region.
103
104 SetClip( savedClipRegion );
105 DisposeRgn( savedClipRegion );
106 }
107 break;
108 case lHiliteMsg:
109
110 // Hilite or unhilite the cell. Paint the cell contents with the
111 // appropriate QuickDraw transform mode.
112
113 GetPort( &grafPtr );
114 savedPenMode = GetPortPenMode( (CGrafPtr)grafPtr );
115 SetPortPenMode( (CGrafPtr)grafPtr, hilitetransfermode );
116 PaintRect( drawRect );
117 SetPortPenMode( (CGrafPtr)grafPtr, savedPenMode );
118 break;
119 default :
120 break ;
121 }
122 SetPort(savePort);
123 }
124
125 extern "C" void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon) ;
126 const short kwxMacListWithVerticalScrollbar = 128 ;
127 const short kwxMacListItemHeight = 14 ;
128
129 // ============================================================================
130 // list box control implementation
131 // ============================================================================
132
133 // Listbox item
134 wxListBox::wxListBox()
135 {
136 m_noItems = 0;
137 m_selected = 0;
138 m_macList = NULL ;
139 }
140
141 static ListDefUPP macListDefUPP = NULL ;
142
143 bool wxListBox::Create(wxWindow *parent, wxWindowID id,
144 const wxPoint& pos,
145 const wxSize& size,
146 int n, const wxString choices[],
147 long style,
148 const wxValidator& validator,
149 const wxString& name)
150 {
151 m_noItems = 0 ; // this will be increased by our append command
152 m_selected = 0;
153
154 Rect bounds ;
155 Str255 title ;
156
157 MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ;
158
159 ListDefSpec listDef;
160 listDef.defType = kListDefUserProcType;
161 if ( macListDefUPP == NULL )
162 {
163 macListDefUPP = NewListDefUPP( wxMacListDefinition );
164 }
165 listDef.u.userProc = macListDefUPP ;
166
167 #if TARGET_CARBON
168 Size asize;
169
170
171 CreateListBoxControl( parent->MacGetRootWindow(), &bounds, false, 0, 1, false, true,
172 kwxMacListItemHeight, kwxMacListItemHeight, false, &listDef, &m_macControl );
173
174 GetControlData( (ControlHandle) m_macControl, kControlNoPart, kControlListBoxListHandleTag,
175 sizeof(ListHandle), (Ptr) &m_macList, &asize);
176
177 SetControlReference( (ControlHandle) m_macControl, (long) this);
178 SetControlVisibility( (ControlHandle) m_macControl, false, false);
179
180 #else
181
182 long result ;
183
184 m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false ,
185 kwxMacListWithVerticalScrollbar , 0 , 0,
186 kControlListBoxProc , (long) this ) ;
187 ::GetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlListBoxListHandleTag ,
188 sizeof( ListHandle ) , (char*) &m_macList , &result ) ;
189
190 HLock( (Handle) m_macList ) ;
191 ldefHandle ldef ;
192 ldef = (ldefHandle) NewHandle( sizeof(ldefRec) ) ;
193 if ( (**(ListHandle)m_macList).listDefProc != NULL )
194 {
195 (**ldef).instruction = 0x4EF9; /* JMP instruction */
196 (**ldef).function = (void(*)()) listDef.u.userProc;
197 (**(ListHandle)m_macList).listDefProc = (Handle) ldef ;
198 }
199
200 Point pt = (**(ListHandle)m_macList).cellSize ;
201 pt.v = kwxMacListItemHeight ;
202 LCellSize( pt , (ListHandle)m_macList ) ;
203 LAddColumn( 1 , 0 , (ListHandle)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((ListHandle)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 , (ListHandle)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( (**(ListHandle)m_macList).listDefProc ) ;
239 (**(ListHandle)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( (ControlHandle) 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 wxControl::Refresh( eraseBack , rect ) ;
591 // MacRedrawControl() ;
592 }
593
594 #if wxUSE_OWNER_DRAWN
595
596 class wxListBoxItem : public wxOwnerDrawn
597 {
598 public:
599 wxListBoxItem(const wxString& str = "");
600 };
601
602 wxListBoxItem::wxListBoxItem(const wxString& str) : wxOwnerDrawn(str, FALSE)
603 {
604 // no bitmaps/checkmarks
605 SetMarginWidth(0);
606 }
607
608 wxOwnerDrawn *wxListBox::CreateItem(size_t n)
609 {
610 return new wxListBoxItem();
611 }
612
613 #endif //USE_OWNER_DRAWN
614
615 // ============================================================================
616 // list box control implementation
617 // ============================================================================
618
619 void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
620 {
621 wxListBox* list;
622 // typecast our refCon
623 list = (wxListBox*)refCon;
624
625 MoveTo(cellRect->left + 4 , cellRect->top + 10 );
626 const wxString text = list->m_stringArray[lCell.v] ;
627 ::TextFont( kFontIDMonaco ) ;
628 ::TextSize( 9 );
629 ::TextFace( 0 ) ;
630 DrawText(text, 0 , text.Length());
631
632 }
633
634 void wxListBox::MacDelete( int N )
635 {
636 LDelRow( 1 , N , (ListHandle)m_macList) ;
637 Refresh();
638 }
639
640 void wxListBox::MacInsert( int n , const char * text)
641 {
642 Cell cell = { 0 , 0 } ;
643 cell.v = n ;
644 LAddRow( 1 , cell.v , (ListHandle)m_macList ) ;
645 // LSetCell(text, strlen(text), cell, m_macList);
646 Refresh();
647 }
648
649 void wxListBox::MacAppend( const char * text)
650 {
651 Cell cell = { 0 , 0 } ;
652 cell.v = (**(ListHandle)m_macList).dataBounds.bottom ;
653 LAddRow( 1 , cell.v , (ListHandle)m_macList ) ;
654 // LSetCell(text, strlen(text), cell, m_macList);
655 Refresh();
656 }
657
658 void wxListBox::MacClear()
659 {
660 LDelRow( (**(ListHandle)m_macList).dataBounds.bottom , 0 ,(ListHandle) m_macList ) ;
661 Refresh();
662 }
663
664 void wxListBox::MacSetSelection( int n , bool select )
665 {
666 Cell cell = { 0 , 0 } ;
667 if ( ! (m_windowStyle & wxLB_MULTIPLE) )
668 {
669 if ( LGetSelect( true , &cell , (ListHandle)m_macList ) )
670 {
671 LSetSelect( false , cell , (ListHandle)m_macList ) ;
672 }
673 }
674
675 cell.v = n ;
676 LSetSelect( select , cell , (ListHandle)m_macList ) ;
677 LAutoScroll( (ListHandle)m_macList ) ;
678 Refresh();
679 }
680
681 bool wxListBox::MacIsSelected( int n ) const
682 {
683 Cell cell = { 0 , 0 } ;
684 cell.v = n ;
685 return LGetSelect( false , &cell , (ListHandle)m_macList ) ;
686 }
687
688 void wxListBox::MacDestroy()
689 {
690 // DisposeExtLDEFInfo( m_macList ) ;
691 }
692
693 int wxListBox::MacGetSelection() const
694 {
695 Cell cell = { 0 , 0 } ;
696 if ( LGetSelect( true , &cell , (ListHandle)m_macList ) )
697 return cell.v ;
698 else
699 return -1 ;
700 }
701
702 int wxListBox::MacGetSelections( wxArrayInt& aSelections ) const
703 {
704 int no_sel = 0 ;
705
706 aSelections.Empty();
707
708 Cell cell = { 0 , 0 } ;
709 cell.v = 0 ;
710
711 while ( LGetSelect( true , &cell ,(ListHandle) m_macList ) )
712 {
713 aSelections.Add( cell.v ) ;
714 no_sel++ ;
715 cell.v++ ;
716 }
717 return no_sel ;
718 }
719
720 void wxListBox::MacSet( int n , const char * text )
721 {
722 // our implementation does not store anything in the list
723 // so we just have to redraw
724 Cell cell = { 0 , 0 } ;
725 cell.v = n ;
726 // LSetCell(text, strlen(text), cell, m_macList);
727 Refresh();
728 }
729
730 void wxListBox::MacScrollTo( int n )
731 {
732 // TODO implement scrolling
733 }
734
735 void wxListBox::OnSize( const wxSizeEvent &event)
736 {
737 Point pt;
738
739 #if TARGET_CARBON
740 GetListCellSize(m_macList, &pt);
741 #else
742 pt = (**(ListHandle)m_macList).cellSize ;
743 #endif
744 pt.h = m_width - 15 ;
745 LCellSize( pt , (ListHandle)m_macList ) ;
746 }
747
748 void wxListBox::MacHandleControlClick( WXWidget control , wxInt16 controlpart )
749 {
750 Boolean wasDoubleClick = false ;
751 long result ;
752
753 ::GetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlListBoxDoubleClickTag , sizeof( wasDoubleClick ) , (char*) &wasDoubleClick , &result ) ;
754 if ( !wasDoubleClick )
755 {
756 MacDoClick() ;
757 }
758 else
759 {
760 MacDoDoubleClick() ;
761 }
762 }
763
764 void wxListBox::MacSetRedraw( bool doDraw )
765 {
766 LSetDrawingMode( doDraw , (ListHandle)m_macList ) ;
767
768 }
769
770 void wxListBox::MacDoClick()
771 {
772 wxArrayInt aSelections;
773 int n, count = GetSelections(aSelections);
774
775 if ( count == m_selectionPreImage.GetCount() )
776 {
777 bool hasChanged = false ;
778 for ( int i = 0 ; i < count ; ++i )
779 {
780 if ( aSelections[i] != m_selectionPreImage[i] )
781 {
782 hasChanged = true ;
783 break ;
784 }
785 }
786 if ( !hasChanged )
787 {
788 return ;
789 }
790 }
791
792 m_selectionPreImage = aSelections;
793
794 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId);
795 event.SetEventObject( this );
796
797 if ( count > 0 )
798 {
799 n = aSelections[0];
800 if ( HasClientObjectData() )
801 event.SetClientObject( GetClientObject(n) );
802 else if ( HasClientUntypedData() )
803 event.SetClientData( GetClientData(n) );
804 event.SetString( GetString(n) );
805 }
806 else
807 {
808 n = -1;
809 }
810
811 event.m_commandInt = n;
812
813 GetEventHandler()->ProcessEvent(event);
814 }
815
816 void wxListBox::MacDoDoubleClick()
817 {
818 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, m_windowId);
819 event.SetEventObject( this );
820 GetEventHandler()->ProcessEvent(event) ;
821 }