]> git.saurik.com Git - wxWidgets.git/blame - src/mac/listbox.cpp
change to /usr/share/wx/version
[wxWidgets.git] / src / mac / listbox.cpp
CommitLineData
e9576ca5
SC
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
03e11df5 16#include "wx/app.h"
e9576ca5
SC
17#include "wx/listbox.h"
18#include "wx/settings.h"
19#include "wx/dynarray.h"
20#include "wx/log.h"
21
519cb848 22#include "wx/utils.h"
60149370 23#ifndef __DARWIN__
e42e45a9 24// #include "extldef.h"
03e11df5 25#endif
519cb848 26
2f1ae414 27#if !USE_SHARED_LIBRARY
e9576ca5 28 IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl)
519cb848
SC
29
30BEGIN_EVENT_TABLE(wxListBox, wxControl)
31 EVT_SIZE( wxListBox::OnSize )
32END_EVENT_TABLE()
2f1ae414 33#endif
e9576ca5 34
d497dca4 35#include "wx/mac/uma.h"
519cb848 36
e42e45a9
SC
37
38typedef struct {
39 unsigned short instruction;
40 void (*function)();
41} ldefRec, *ldefPtr, **ldefHandle;
42
43extern "C"
44{
45static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect *drawRect,
46 Cell cell, short dataOffset, short dataLength,
47 ListHandle listHandle ) ;
48}
49
50static 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 ClipRect( drawRect );
85 EraseRect( drawRect );
86
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
519cb848
SC
127extern "C" void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon) ;
128const short kwxMacListWithVerticalScrollbar = 128 ;
129
e9576ca5
SC
130// ============================================================================
131// list box control implementation
132// ============================================================================
133
134// Listbox item
135wxListBox::wxListBox()
136{
137 m_noItems = 0;
138 m_selected = 0;
2f1ae414 139 m_macList = NULL ;
e9576ca5
SC
140}
141
e42e45a9
SC
142static ListDefUPP macListDefUPP = NULL ;
143
e9576ca5
SC
144bool 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{
60149370
GD
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 ) ;
e9576ca5 159
60149370 160 ListDefSpec listDef;
e42e45a9
SC
161 listDef.defType = kListDefUserProcType;
162 if ( macListDefUPP == NULL )
163 {
164 macListDefUPP = NewListDefUPP( wxMacListDefinition );
165 }
166 listDef.u.userProc = macListDefUPP ;
167#if TARGET_CARBON
60149370 168 Size asize;
519cb848 169
519cb848 170
60149370
GD
171 CreateListBoxControl( parent->GetMacRootWindow(), &bounds, false, 0, 1, false, true,
172 14, 14, false, &listDef, &m_macControl );
519cb848 173
60149370
GD
174 GetControlData(m_macControl, kControlNoPart, kControlListBoxListHandleTag,
175 sizeof(ListHandle), (Ptr) &m_macList, &asize);
519cb848 176
60149370
GD
177 SetControlReference(m_macControl, (long) this);
178 SetControlVisibility(m_macControl, false, false);
519cb848 179
60149370
GD
180#else
181 long result ;
182
72055702 183 m_macControl = ::NewControl( parent->GetMacRootWindow() , &bounds , title , false ,
60149370
GD
184 kwxMacListWithVerticalScrollbar , 0 , 0,
185 kControlListBoxProc , (long) this ) ;
72055702 186 ::GetControlData( m_macControl , kControlNoPart , kControlListBoxListHandleTag ,
60149370
GD
187 sizeof( ListHandle ) , (char*) &m_macList , &result ) ;
188
189 HLock( (Handle) m_macList ) ;
e42e45a9
SC
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 ) ;
60149370 202
e42e45a9
SC
203 LAddColumn( 1 , 0 , m_macList ) ;
204#endif
205 OptionBits options = 0;
60149370
GD
206 if ( style & wxLB_MULTIPLE )
207 {
e42e45a9 208 options += lNoExtend ;
60149370
GD
209 }
210 else if ( style & wxLB_EXTENDED )
211 {
e42e45a9 212 options += lExtendDrag ;
60149370
GD
213 }
214 else
215 {
e42e45a9 216 options = lOnlyOne ;
60149370 217 }
e42e45a9 218 SetListSelectionFlags(m_macList, options);
60149370
GD
219
220 MacPostControlCreate() ;
221
222 for ( int i = 0 ; i < n ; i++ )
223 {
e42e45a9 224 Append( choices[i] ) ;
60149370
GD
225 }
226
227 LSetDrawingMode( true , m_macList ) ;
519cb848 228
60149370 229 return TRUE;
e9576ca5
SC
230}
231
232wxListBox::~wxListBox()
233{
e7549107 234 Free() ;
2f1ae414
SC
235 if ( m_macList )
236 {
60149370 237#if !TARGET_CARBON
e42e45a9
SC
238 DisposeHandle( (**m_macList).listDefProc ) ;
239 (**m_macList).listDefProc = NULL ;
60149370
GD
240#endif
241 m_macList = NULL ;
2f1ae414 242 }
e9576ca5
SC
243}
244
e7549107 245void wxListBox::Free()
e9576ca5 246{
e7549107
SC
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 }
e9576ca5
SC
266}
267
e7549107 268void wxListBox::DoSetFirstItem(int N)
e9576ca5 269{
e7549107 270 MacScrollTo( N ) ;
e9576ca5
SC
271}
272
273void wxListBox::Delete(int N)
274{
e7549107
SC
275 wxCHECK_RET( N >= 0 && N < m_noItems,
276 wxT("invalid index in wxListBox::Delete") );
277
278#if wxUSE_OWNER_DRAWN
279 delete m_aItems[N];
0baac61e 280 m_aItems.RemoveAt(N);
e7549107
SC
281#else // !wxUSE_OWNER_DRAWN
282 if ( HasClientObjectData() )
283 {
284 delete GetClientObject(N);
285 }
286#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
519cb848 287 m_stringArray.Remove( N ) ;
3ef585df 288 m_dataArray.RemoveAt( N ) ;
2f1ae414 289 m_noItems --;
519cb848
SC
290
291 MacDelete( N ) ;
e9576ca5
SC
292}
293
e7549107 294int wxListBox::DoAppend(const wxString& item)
e9576ca5 295{
e7549107 296 int index = m_noItems ;
519cb848
SC
297 if( wxApp::s_macDefaultEncodingIsPC )
298 {
299 m_stringArray.Add( wxMacMakeMacStringFromPC( item ) ) ;
b81abd0d 300 m_dataArray.Add( NULL );
519cb848 301 }
b81abd0d 302 else {
519cb848 303 m_stringArray.Add( item ) ;
b81abd0d
GD
304 m_dataArray.Add( NULL );
305 }
e7549107 306 m_noItems ++;
5b781a67 307 DoSetItemClientData( index , NULL ) ;
519cb848 308 MacAppend( item ) ;
e7549107 309
e7549107 310 return index ;
e9576ca5
SC
311}
312
e7549107
SC
313void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData)
314{
315 MacSetRedraw( false ) ;
519cb848 316 Clear() ;
e7549107
SC
317 int n = choices.GetCount();
318
519cb848
SC
319 for( int i = 0 ; i < n ; ++i )
320 {
321 if ( clientData )
e7549107
SC
322 {
323#if wxUSE_OWNER_DRAWN
324 wxASSERT_MSG(clientData[i] == NULL,
325 wxT("Can't use client data with owner-drawn listboxes"));
326#else // !wxUSE_OWNER_DRAWN
8208e181 327 Append( choices[i] , clientData[i] ) ;
e7549107
SC
328 #endif
329 }
519cb848
SC
330 else
331 Append( choices[i] ) ;
332 }
e7549107
SC
333
334#if wxUSE_OWNER_DRAWN
335 if ( m_windowStyle & wxLB_OWNERDRAW ) {
336 // first delete old items
337 size_t ui = m_aItems.Count();
338 while ( ui-- != 0 ) {
339 delete m_aItems[ui];
340 }
341 m_aItems.Empty();
342
343 // then create new ones
344 for ( ui = 0; ui < (size_t)m_noItems; ui++ ) {
345 wxOwnerDrawn *pNewItem = CreateItem(ui);
346 pNewItem->SetName(choices[ui]);
347 m_aItems.Add(pNewItem);
348 }
349 }
350#endif // wxUSE_OWNER_DRAWN
351 MacSetRedraw( true ) ;
352}
353
354bool wxListBox::HasMultipleSelection() const
355{
356 return (m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED);
e9576ca5
SC
357}
358
519cb848 359int wxListBox::FindString(const wxString& st) const
e9576ca5 360{
519cb848
SC
361 wxString s ;
362 if( wxApp::s_macDefaultEncodingIsPC )
363 {
364 s = wxMacMakeMacStringFromPC( st ) ;
365 }
366 else
367 s = st ;
368
369 if ( s.Right(1) == "*" )
370 {
371 wxString search = s.Left( s.Length() - 1 ) ;
372 int len = search.Length() ;
03e11df5
GD
373 Str255 s1 , s2 ;
374
375#if TARGET_CARBON
376 c2pstrcpy( (StringPtr) s2 , search.c_str() ) ;
377#else
378 strcpy( (char *) s2 , search.c_str() ) ;
379 c2pstr( (char *) s2 ) ;
380#endif
381
2f1ae414
SC
382 for ( int i = 0 ; i < m_noItems ; ++ i )
383 {
03e11df5
GD
384#if TARGET_CARBON
385 c2pstrcpy( (StringPtr) s1 , m_stringArray[i].Left( len ).c_str() ) ;
386#else
387 strcpy( (char *) s1 , m_stringArray[i].Left( len ).c_str() ) ;
388 c2pstr( (char *) s1 ) ;
389#endif
2f1ae414
SC
390 if ( EqualString( s1 , s2 , false , false ) )
391 return i ;
392 }
51a229c6 393 if ( s.Left(1) == "*" && s.Length() > 1 )
5b781a67
SC
394 {
395 s.MakeLower() ;
396 for ( int i = 0 ; i < m_noItems ; ++i )
397 {
398 if ( GetString(i).Lower().Matches(s) )
399 return i ;
400 }
401 }
402
519cb848
SC
403 }
404 else
405 {
2f1ae414 406 Str255 s1 , s2 ;
03e11df5
GD
407
408#if TARGET_CARBON
409 c2pstrcpy( (StringPtr) s2 , s.c_str() ) ;
410#else
411 strcpy( (char *) s2 , s.c_str() ) ;
412 c2pstr( (char *) s2 ) ;
413#endif
414
2f1ae414
SC
415 for ( int i = 0 ; i < m_noItems ; ++ i )
416 {
03e11df5
GD
417#if TARGET_CARBON
418 c2pstrcpy( (StringPtr) s1 , m_stringArray[i].c_str() ) ;
419#else
420 strcpy( (char *) s1 , m_stringArray[i].c_str() ) ;
421 c2pstr( (char *) s1 ) ;
422#endif
2f1ae414
SC
423 if ( EqualString( s1 , s2 , false , false ) )
424 return i ;
425 }
519cb848
SC
426 }
427 return -1;
e9576ca5
SC
428}
429
430void wxListBox::Clear()
431{
e7549107 432 Free();
e9576ca5 433 m_noItems = 0;
519cb848
SC
434 m_stringArray.Empty() ;
435 m_dataArray.Empty() ;
436 MacClear() ;
e9576ca5
SC
437}
438
439void wxListBox::SetSelection(int N, bool select)
440{
519cb848
SC
441 wxCHECK_RET( N >= 0 && N < m_noItems,
442 "invalid index in wxListBox::SetSelection" );
ccf0e7f6
SC
443 MacSetSelection( N , select ) ;
444 GetSelections( m_selectionPreImage ) ;
e9576ca5
SC
445}
446
e7549107 447bool wxListBox::IsSelected(int N) const
e9576ca5 448{
519cb848
SC
449 wxCHECK_MSG( N >= 0 && N < m_noItems, FALSE,
450 "invalid index in wxListBox::Selected" );
451
ccf0e7f6 452 return MacIsSelected( N ) ;
e9576ca5
SC
453}
454
e7549107 455void *wxListBox::DoGetItemClientData(int N) const
e9576ca5 456{
519cb848 457 wxCHECK_MSG( N >= 0 && N < m_noItems, NULL,
60149370 458 wxT("invalid index in wxListBox::GetClientData"));
519cb848 459
e7549107 460 return (void *)m_dataArray[N];
e9576ca5
SC
461}
462
51abe921
SC
463wxClientData *wxListBox::DoGetItemClientObject(int N) const
464{
465 return (wxClientData *) DoGetItemClientData( N ) ;
466}
467
e7549107 468void wxListBox::DoSetItemClientData(int N, void *Client_data)
e9576ca5 469{
519cb848
SC
470 wxCHECK_RET( N >= 0 && N < m_noItems,
471 "invalid index in wxListBox::SetClientData" );
472
e7549107
SC
473#if wxUSE_OWNER_DRAWN
474 if ( m_windowStyle & wxLB_OWNERDRAW )
475 {
476 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
477 // in OnMeasure/OnDraw.
478 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
479 }
480#endif // wxUSE_OWNER_DRAWN
8208e181
SC
481 wxASSERT_MSG( m_dataArray.GetCount() >= N , "invalid client_data array" ) ;
482
483 if ( m_dataArray.GetCount() > N )
484 {
485 m_dataArray[N] = (char*) Client_data ;
2f1ae414 486 }
8208e181
SC
487 else
488 {
489 m_dataArray.Add( (char*) Client_data ) ;
490 }
e7549107
SC
491}
492
493void wxListBox::DoSetItemClientObject(int n, wxClientData* clientData)
494{
495 DoSetItemClientData(n, clientData);
e9576ca5
SC
496}
497
498// Return number of selections and an array of selected integers
499int wxListBox::GetSelections(wxArrayInt& aSelections) const
500{
519cb848 501 return MacGetSelections( aSelections ) ;
e9576ca5
SC
502}
503
504// Get single selection, for single choice list items
505int wxListBox::GetSelection() const
506{
519cb848 507 return MacGetSelection() ;
e9576ca5
SC
508}
509
510// Find string for position
511wxString wxListBox::GetString(int N) const
512{
519cb848
SC
513 if( wxApp::s_macDefaultEncodingIsPC )
514 {
515 return wxMacMakePCStringFromMac( m_stringArray[N] ) ;
516 }
517 else
518 return m_stringArray[N] ;
e9576ca5
SC
519}
520
e7549107 521void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
e9576ca5 522{
e7549107
SC
523 wxCHECK_RET( pos >= 0 && pos <= m_noItems,
524 wxT("invalid index in wxListBox::InsertItems") );
525
526 int nItems = items.GetCount();
527
519cb848
SC
528 for ( int i = 0 ; i < nItems ; i++ )
529 {
530 m_stringArray.Insert( items[i] , pos + i ) ;
531 m_dataArray.Insert( NULL , pos + i ) ;
532 MacInsert( pos + i , items[i] ) ;
533 }
e9576ca5 534
519cb848 535 m_noItems += nItems;
e9576ca5
SC
536}
537
538void wxListBox::SetString(int N, const wxString& s)
539{
2f1ae414
SC
540 wxString str ;
541 if( wxApp::s_macDefaultEncodingIsPC )
542 {
543 str = wxMacMakeMacStringFromPC( s ) ;
544 }
545 else
546 str = s ;
547 m_stringArray[N] = str ;
519cb848 548 MacSet( N , s ) ;
e9576ca5
SC
549}
550
37e2cb08 551wxSize wxListBox::DoGetBestSize() const
e9576ca5 552{
e7549107 553 return wxSize(100, 100);
e9576ca5
SC
554}
555
51abe921
SC
556int wxListBox::GetCount() const
557{
558 return m_noItems;
559}
560
561void wxListBox::SetupColours()
562{
563 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW));
564 SetForegroundColour(GetParent()->GetForegroundColour());
565}
566
60149370
GD
567void wxListBox::Refresh(bool eraseBack, const wxRect *rect)
568{
569 // Set up port
570 WindowRef rootwindow = GetMacRootWindow() ;
571 wxWindow* wxrootwindow = wxFindWinFromMacWindow( rootwindow ) ;
572 wxMacDrawingHelper focus( wxrootwindow );
573
574 UMADrawControl(m_macControl);
575}
576
51abe921
SC
577#if wxUSE_OWNER_DRAWN
578
579class wxListBoxItem : public wxOwnerDrawn
580{
581public:
582 wxListBoxItem(const wxString& str = "");
583};
584
585wxListBoxItem::wxListBoxItem(const wxString& str) : wxOwnerDrawn(str, FALSE)
586{
587 // no bitmaps/checkmarks
588 SetMarginWidth(0);
589}
590
591wxOwnerDrawn *wxListBox::CreateItem(size_t n)
592{
593 return new wxListBoxItem();
594}
595
596#endif //USE_OWNER_DRAWN
e9576ca5 597
519cb848
SC
598// ============================================================================
599// list box control implementation
600// ============================================================================
601
602void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
603{
604 wxListBox* list;
605 // typecast our refCon
606 list = (wxListBox*)refCon;
607
608 MoveTo(cellRect->left + 4 , cellRect->top + 10 );
609 const wxString text = list->m_stringArray[lCell.v] ;
610 ::TextFont( kFontIDMonaco ) ;
611 ::TextSize( 9 );
612 ::TextFace( 0 ) ;
613 DrawText(text, 0 , text.Length());
614
615}
616
617void wxListBox::MacDelete( int N )
618{
60149370
GD
619 LDelRow( 1 , N , m_macList) ;
620 Refresh();
519cb848
SC
621}
622
623void wxListBox::MacInsert( int n , const char * text)
624{
60149370
GD
625 Cell cell = { 0 , 0 } ;
626 cell.v = n ;
627 LAddRow( 1 , cell.v , m_macList ) ;
e42e45a9 628// LSetCell(text, strlen(text), cell, m_macList);
60149370 629 Refresh();
519cb848
SC
630}
631
632void wxListBox::MacAppend( const char * text)
633{
60149370
GD
634 Cell cell = { 0 , 0 } ;
635 cell.v = (**m_macList).dataBounds.bottom ;
636 LAddRow( 1 , cell.v , m_macList ) ;
e42e45a9 637 // LSetCell(text, strlen(text), cell, m_macList);
60149370 638 Refresh();
519cb848
SC
639}
640
641void wxListBox::MacClear()
642{
60149370
GD
643 LDelRow( (**m_macList).dataBounds.bottom , 0 , m_macList ) ;
644 Refresh();
519cb848
SC
645}
646
647void wxListBox::MacSetSelection( int n , bool select )
648{
649 Cell cell = { 0 , 0 } ;
f47db8f0 650 if ( ! (m_windowStyle & wxLB_MULTIPLE) )
519cb848 651 {
f47db8f0
SC
652 if ( LGetSelect( true , &cell , m_macList ) )
653 {
654 LSetSelect( false , cell , m_macList ) ;
655 }
519cb848
SC
656 }
657
658 cell.v = n ;
659 LSetSelect( select , cell , m_macList ) ;
660 LAutoScroll( m_macList ) ;
60149370 661 Refresh();
519cb848
SC
662}
663
664bool wxListBox::MacIsSelected( int n ) const
665{
666 Cell cell = { 0 , 0 } ;
667 cell.v = n ;
668 return LGetSelect( false , &cell , m_macList ) ;
669}
670
671void wxListBox::MacDestroy()
672{
60149370 673// DisposeExtLDEFInfo( m_macList ) ;
519cb848
SC
674}
675
676int wxListBox::MacGetSelection() const
677{
678 Cell cell = { 0 , 0 } ;
679 if ( LGetSelect( true , &cell , m_macList ) )
680 return cell.v ;
681 else
682 return -1 ;
683}
684
685int wxListBox::MacGetSelections( wxArrayInt& aSelections ) const
686{
687 int no_sel = 0 ;
688
689 aSelections.Empty();
690
691 Cell cell = { 0 , 0 } ;
692 cell.v = 0 ;
693
694 while ( LGetSelect( true , &cell , m_macList ) )
695 {
696 aSelections.Add( cell.v ) ;
697 no_sel++ ;
698 cell.v++ ;
699 }
700 return no_sel ;
701}
702
703void wxListBox::MacSet( int n , const char * text )
704{
705 // our implementation does not store anything in the list
706 // so we just have to redraw
707 Cell cell = { 0 , 0 } ;
708 cell.v = n ;
e42e45a9 709// LSetCell(text, strlen(text), cell, m_macList);
60149370 710 Refresh();
519cb848
SC
711}
712
713void wxListBox::MacScrollTo( int n )
714{
715 // TODO implement scrolling
716}
717
718void wxListBox::OnSize( const wxSizeEvent &event)
719{
60149370
GD
720 Point pt;
721
722#if TARGET_CARBON
723 GetListCellSize(m_macList, &pt);
724#else
725 pt = (**m_macList).cellSize ;
726#endif
727 pt.h = m_width - 15 ;
728 LCellSize( pt , m_macList ) ;
519cb848
SC
729}
730
731void wxListBox::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
732{
733 Boolean wasDoubleClick = false ;
734 long result ;
735
72055702 736 ::GetControlData( m_macControl , kControlNoPart , kControlListBoxDoubleClickTag , sizeof( wasDoubleClick ) , (char*) &wasDoubleClick , &result ) ;
519cb848
SC
737 if ( !wasDoubleClick )
738 {
739 MacDoClick() ;
740 }
741 else
742 {
743 MacDoDoubleClick() ;
744 }
745}
746
747void wxListBox::MacSetRedraw( bool doDraw )
748{
749 LSetDrawingMode( doDraw , m_macList ) ;
750
751}
752
753void wxListBox::MacDoClick()
754{
519cb848 755 wxArrayInt aSelections;
e7549107 756 int n, count = GetSelections(aSelections);
ccf0e7f6
SC
757
758 if ( count == m_selectionPreImage.GetCount() )
759 {
760 bool hasChanged = false ;
761 for ( int i = 0 ; i < count ; ++i )
762 {
763 if ( aSelections[i] != m_selectionPreImage[i] )
764 {
765 hasChanged = true ;
766 break ;
767 }
768 }
769 if ( !hasChanged )
770 return ;
771 }
772
773 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId);
774 event.SetEventObject( this );
775
519cb848
SC
776 if ( count > 0 )
777 {
7c74e7fe
SC
778 n = aSelections[0];
779 if ( HasClientObjectData() )
e7549107
SC
780 event.SetClientObject( GetClientObject(n) );
781 else if ( HasClientUntypedData() )
782 event.SetClientData( GetClientData(n) );
783 event.SetString( GetString(n) );
519cb848
SC
784 }
785 else
786 {
e7549107 787 n = -1;
519cb848
SC
788 }
789
e7549107
SC
790 event.m_commandInt = n;
791
792 GetEventHandler()->ProcessEvent(event);
519cb848
SC
793}
794
795void wxListBox::MacDoDoubleClick()
796{
797 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, m_windowId);
798 event.SetEventObject( this );
799 GetEventHandler()->ProcessEvent(event) ;
800}