]> git.saurik.com Git - wxWidgets.git/blame - src/mac/listbox.cpp
toplevel adaptions
[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)
a8e6bf8a 31 EVT_SIZE( wxListBox::OnSize )
519cb848 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,
a8e6bf8a
RR
46 Cell cell, short dataOffset, short dataLength,
47 ListHandle listHandle ) ;
e42e45a9
SC
48}
49
50static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect *drawRect,
a8e6bf8a
RR
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;
e42e45a9
SC
60 GetPort(&savePort);
61 SetPort((**listHandle).port);
62 grafPtr = (**listHandle).port ;
a8e6bf8a
RR
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 ) ;
e42e45a9 92
a8e6bf8a
RR
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);
e42e45a9
SC
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 }
a8e6bf8a 166 listDef.u.userProc = macListDefUPP ;
e42e45a9 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 180#else
a8e6bf8a 181 long result ;
60149370 182
72055702 183 m_macControl = ::NewControl( parent->GetMacRootWindow() , &bounds , title , false ,
a8e6bf8a
RR
184 kwxMacListWithVerticalScrollbar , 0 , 0,
185 kControlListBoxProc , (long) this ) ;
72055702 186 ::GetControlData( m_macControl , kControlNoPart , kControlListBoxListHandleTag ,
a8e6bf8a 187 sizeof( ListHandle ) , (char*) &m_macList , &result ) ;
60149370
GD
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 {
a8e6bf8a 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{
a8e6bf8a
RR
234 Free() ;
235 if ( m_macList )
236 {
60149370 237#if !TARGET_CARBON
e42e45a9
SC
238 DisposeHandle( (**m_macList).listDefProc ) ;
239 (**m_macList).listDefProc = NULL ;
60149370 240#endif
a8e6bf8a
RR
241 m_macList = NULL ;
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
8614041b
SC
268void wxListBox::DoSetSize(int x, int y,
269 int width, int height,
270 int sizeFlags )
271{
a8e6bf8a 272 wxControl::DoSetSize( x , y , width , height , sizeFlags ) ;
8614041b 273#if TARGET_CARBON
a8e6bf8a
RR
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 }
8614041b
SC
287#endif
288}
e7549107 289void wxListBox::DoSetFirstItem(int N)
e9576ca5 290{
a8e6bf8a 291 MacScrollTo( N ) ;
e9576ca5
SC
292}
293
294void wxListBox::Delete(int N)
295{
e7549107
SC
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];
0baac61e 301 m_aItems.RemoveAt(N);
e7549107
SC
302#else // !wxUSE_OWNER_DRAWN
303 if ( HasClientObjectData() )
304 {
305 delete GetClientObject(N);
306 }
307#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
a8e6bf8a
RR
308 m_stringArray.Remove( N ) ;
309 m_dataArray.RemoveAt( N ) ;
310 m_noItems --;
311
312 MacDelete( N ) ;
e9576ca5
SC
313}
314
e7549107 315int wxListBox::DoAppend(const wxString& item)
e9576ca5 316{
a8e6bf8a
RR
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 ) ;
e7549107 330
a8e6bf8a 331 return index ;
e9576ca5
SC
332}
333
e7549107
SC
334void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData)
335{
336 MacSetRedraw( false ) ;
519cb848 337 Clear() ;
e7549107
SC
338 int n = choices.GetCount();
339
519cb848
SC
340 for( int i = 0 ; i < n ; ++i )
341 {
a8e6bf8a
RR
342 if ( clientData )
343 {
e7549107
SC
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
a8e6bf8a 348 Append( choices[i] , clientData[i] ) ;
e7549107 349 #endif
a8e6bf8a
RR
350 }
351 else
352 Append( choices[i] ) ;
519cb848 353 }
e7549107
SC
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
375bool wxListBox::HasMultipleSelection() const
376{
377 return (m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED);
e9576ca5
SC
378}
379
519cb848 380int wxListBox::FindString(const wxString& st) const
e9576ca5 381{
a8e6bf8a
RR
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 ;
03e11df5
GD
395
396#if TARGET_CARBON
a8e6bf8a 397 c2pstrcpy( (StringPtr) s2 , search.c_str() ) ;
03e11df5 398#else
a8e6bf8a
RR
399 strcpy( (char *) s2 , search.c_str() ) ;
400 c2pstr( (char *) s2 ) ;
03e11df5
GD
401#endif
402
a8e6bf8a
RR
403 for ( int i = 0 ; i < m_noItems ; ++ i )
404 {
03e11df5 405#if TARGET_CARBON
a8e6bf8a 406 c2pstrcpy( (StringPtr) s1 , m_stringArray[i].Left( len ).c_str() ) ;
03e11df5 407#else
a8e6bf8a
RR
408 strcpy( (char *) s1 , m_stringArray[i].Left( len ).c_str() ) ;
409 c2pstr( (char *) s1 ) ;
03e11df5 410#endif
a8e6bf8a
RR
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 ;
03e11df5
GD
428
429#if TARGET_CARBON
a8e6bf8a 430 c2pstrcpy( (StringPtr) s2 , s.c_str() ) ;
03e11df5 431#else
a8e6bf8a
RR
432 strcpy( (char *) s2 , s.c_str() ) ;
433 c2pstr( (char *) s2 ) ;
03e11df5
GD
434#endif
435
a8e6bf8a
RR
436 for ( int i = 0 ; i < m_noItems ; ++ i )
437 {
03e11df5 438#if TARGET_CARBON
a8e6bf8a 439 c2pstrcpy( (StringPtr) s1 , m_stringArray[i].c_str() ) ;
03e11df5 440#else
a8e6bf8a
RR
441 strcpy( (char *) s1 , m_stringArray[i].c_str() ) ;
442 c2pstr( (char *) s1 ) ;
03e11df5 443#endif
a8e6bf8a
RR
444 if ( EqualString( s1 , s2 , false , false ) )
445 return i ;
446 }
519cb848
SC
447 }
448 return -1;
e9576ca5
SC
449}
450
451void wxListBox::Clear()
452{
e7549107 453 Free();
e9576ca5 454 m_noItems = 0;
519cb848
SC
455 m_stringArray.Empty() ;
456 m_dataArray.Empty() ;
457 MacClear() ;
e9576ca5
SC
458}
459
460void wxListBox::SetSelection(int N, bool select)
461{
519cb848
SC
462 wxCHECK_RET( N >= 0 && N < m_noItems,
463 "invalid index in wxListBox::SetSelection" );
a8e6bf8a
RR
464 MacSetSelection( N , select ) ;
465 GetSelections( m_selectionPreImage ) ;
e9576ca5
SC
466}
467
e7549107 468bool wxListBox::IsSelected(int N) const
e9576ca5 469{
519cb848
SC
470 wxCHECK_MSG( N >= 0 && N < m_noItems, FALSE,
471 "invalid index in wxListBox::Selected" );
472
a8e6bf8a 473 return MacIsSelected( N ) ;
e9576ca5
SC
474}
475
e7549107 476void *wxListBox::DoGetItemClientData(int N) const
e9576ca5 477{
519cb848 478 wxCHECK_MSG( N >= 0 && N < m_noItems, NULL,
60149370 479 wxT("invalid index in wxListBox::GetClientData"));
519cb848 480
e7549107 481 return (void *)m_dataArray[N];
e9576ca5
SC
482}
483
51abe921
SC
484wxClientData *wxListBox::DoGetItemClientObject(int N) const
485{
a8e6bf8a 486 return (wxClientData *) DoGetItemClientData( N ) ;
51abe921
SC
487}
488
e7549107 489void wxListBox::DoSetItemClientData(int N, void *Client_data)
e9576ca5 490{
519cb848
SC
491 wxCHECK_RET( N >= 0 && N < m_noItems,
492 "invalid index in wxListBox::SetClientData" );
493
e7549107
SC
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
a8e6bf8a
RR
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 ;
2f1ae414 507 }
8208e181
SC
508 else
509 {
a8e6bf8a 510 m_dataArray.Add( (char*) Client_data ) ;
8208e181 511 }
e7549107
SC
512}
513
514void wxListBox::DoSetItemClientObject(int n, wxClientData* clientData)
515{
516 DoSetItemClientData(n, clientData);
e9576ca5
SC
517}
518
519// Return number of selections and an array of selected integers
520int wxListBox::GetSelections(wxArrayInt& aSelections) const
521{
a8e6bf8a 522 return MacGetSelections( aSelections ) ;
e9576ca5
SC
523}
524
525// Get single selection, for single choice list items
526int wxListBox::GetSelection() const
527{
a8e6bf8a 528 return MacGetSelection() ;
e9576ca5
SC
529}
530
531// Find string for position
532wxString wxListBox::GetString(int N) const
533{
a8e6bf8a
RR
534 if( wxApp::s_macDefaultEncodingIsPC )
535 {
536 return wxMacMakePCStringFromMac( m_stringArray[N] ) ;
537 }
538 else
539 return m_stringArray[N] ;
e9576ca5
SC
540}
541
e7549107 542void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
e9576ca5 543{
e7549107
SC
544 wxCHECK_RET( pos >= 0 && pos <= m_noItems,
545 wxT("invalid index in wxListBox::InsertItems") );
546
547 int nItems = items.GetCount();
548
a8e6bf8a
RR
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 }
e9576ca5 555
519cb848 556 m_noItems += nItems;
e9576ca5
SC
557}
558
559void wxListBox::SetString(int N, const wxString& s)
560{
a8e6bf8a
RR
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 ) ;
e9576ca5
SC
570}
571
37e2cb08 572wxSize wxListBox::DoGetBestSize() const
e9576ca5 573{
e7549107 574 return wxSize(100, 100);
e9576ca5
SC
575}
576
51abe921
SC
577int wxListBox::GetCount() const
578{
579 return m_noItems;
580}
581
582void wxListBox::SetupColours()
583{
584 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW));
585 SetForegroundColour(GetParent()->GetForegroundColour());
586}
587
60149370
GD
588void wxListBox::Refresh(bool eraseBack, const wxRect *rect)
589{
590 // Set up port
591 WindowRef rootwindow = GetMacRootWindow() ;
592 wxWindow* wxrootwindow = wxFindWinFromMacWindow( rootwindow ) ;
593 wxMacDrawingHelper focus( wxrootwindow );
594
595 UMADrawControl(m_macControl);
596}
597
51abe921
SC
598#if wxUSE_OWNER_DRAWN
599
600class wxListBoxItem : public wxOwnerDrawn
601{
602public:
603 wxListBoxItem(const wxString& str = "");
604};
605
606wxListBoxItem::wxListBoxItem(const wxString& str) : wxOwnerDrawn(str, FALSE)
607{
608 // no bitmaps/checkmarks
609 SetMarginWidth(0);
610}
611
612wxOwnerDrawn *wxListBox::CreateItem(size_t n)
613{
614 return new wxListBoxItem();
615}
616
617#endif //USE_OWNER_DRAWN
e9576ca5 618
519cb848
SC
619// ============================================================================
620// list box control implementation
621// ============================================================================
622
623void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
624{
a8e6bf8a
RR
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
519cb848
SC
636}
637
638void wxListBox::MacDelete( int N )
639{
60149370
GD
640 LDelRow( 1 , N , m_macList) ;
641 Refresh();
519cb848
SC
642}
643
644void wxListBox::MacInsert( int n , const char * text)
645{
60149370
GD
646 Cell cell = { 0 , 0 } ;
647 cell.v = n ;
648 LAddRow( 1 , cell.v , m_macList ) ;
e42e45a9 649// LSetCell(text, strlen(text), cell, m_macList);
60149370 650 Refresh();
519cb848
SC
651}
652
653void wxListBox::MacAppend( const char * text)
654{
60149370
GD
655 Cell cell = { 0 , 0 } ;
656 cell.v = (**m_macList).dataBounds.bottom ;
657 LAddRow( 1 , cell.v , m_macList ) ;
e42e45a9 658 // LSetCell(text, strlen(text), cell, m_macList);
60149370 659 Refresh();
519cb848
SC
660}
661
662void wxListBox::MacClear()
663{
60149370
GD
664 LDelRow( (**m_macList).dataBounds.bottom , 0 , m_macList ) ;
665 Refresh();
519cb848
SC
666}
667
668void wxListBox::MacSetSelection( int n , bool select )
669{
a8e6bf8a
RR
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();
519cb848
SC
683}
684
685bool wxListBox::MacIsSelected( int n ) const
686{
a8e6bf8a
RR
687 Cell cell = { 0 , 0 } ;
688 cell.v = n ;
689 return LGetSelect( false , &cell , m_macList ) ;
519cb848
SC
690}
691
692void wxListBox::MacDestroy()
693{
60149370 694// DisposeExtLDEFInfo( m_macList ) ;
519cb848
SC
695}
696
697int wxListBox::MacGetSelection() const
698{
a8e6bf8a
RR
699 Cell cell = { 0 , 0 } ;
700 if ( LGetSelect( true , &cell , m_macList ) )
701 return cell.v ;
702 else
703 return -1 ;
519cb848
SC
704}
705
706int wxListBox::MacGetSelections( wxArrayInt& aSelections ) const
707{
a8e6bf8a
RR
708 int no_sel = 0 ;
709
519cb848
SC
710 aSelections.Empty();
711
a8e6bf8a
RR
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 ;
519cb848
SC
722}
723
724void wxListBox::MacSet( int n , const char * text )
725{
a8e6bf8a
RR
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();
519cb848
SC
732}
733
734void wxListBox::MacScrollTo( int n )
735{
a8e6bf8a 736 // TODO implement scrolling
519cb848
SC
737}
738
739void wxListBox::OnSize( const wxSizeEvent &event)
740{
60149370
GD
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 ) ;
519cb848
SC
750}
751
752void wxListBox::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
753{
a8e6bf8a
RR
754 Boolean wasDoubleClick = false ;
755 long result ;
519cb848 756
a8e6bf8a
RR
757 ::GetControlData( m_macControl , kControlNoPart , kControlListBoxDoubleClickTag , sizeof( wasDoubleClick ) , (char*) &wasDoubleClick , &result ) ;
758 if ( !wasDoubleClick )
759 {
760 MacDoClick() ;
761 }
762 else
763 {
764 MacDoDoubleClick() ;
765 }
519cb848
SC
766}
767
768void wxListBox::MacSetRedraw( bool doDraw )
769{
a8e6bf8a
RR
770 LSetDrawingMode( doDraw , m_macList ) ;
771
519cb848
SC
772}
773
774void wxListBox::MacDoClick()
775{
a8e6bf8a
RR
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 {
e7549107 812 n = -1;
a8e6bf8a
RR
813 }
814
e7549107
SC
815 event.m_commandInt = n;
816
817 GetEventHandler()->ProcessEvent(event);
519cb848
SC
818}
819
820void wxListBox::MacDoDoubleClick()
821{
822 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, m_windowId);
823 event.SetEventObject( this );
a8e6bf8a 824 GetEventHandler()->ProcessEvent(event) ;
519cb848 825}