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