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