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