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