]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/listbox.cpp
Inital fill in background, removed tabs, -1->wxID_ANY, TRUE->true, FALSE->false
[wxWidgets.git] / src / mac / carbon / listbox.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: listbox.cpp
3 // Purpose: wxListBox
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
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/button.h"
19 #include "wx/settings.h"
20 #include "wx/toplevel.h"
21 #include "wx/dynarray.h"
22 #include "wx/log.h"
23
24 #include "wx/utils.h"
25
26 #if !USE_SHARED_LIBRARY
27 IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl)
28
29 BEGIN_EVENT_TABLE(wxListBox, wxControl)
30 #if !__WXMAC_OSX__
31 EVT_SIZE( wxListBox::OnSize )
32 EVT_CHAR( wxListBox::OnChar )
33 #endif
34 END_EVENT_TABLE()
35 #endif
36
37 #include "wx/mac/uma.h"
38
39 const short kTextColumnId = 1024 ;
40
41 // new databrowserbased version
42
43 // Listbox item
44 wxListBox::wxListBox()
45 {
46 m_noItems = 0;
47 m_selected = 0;
48 m_macList = NULL ;
49 }
50
51 bool wxListBox::Create(wxWindow *parent, wxWindowID id,
52 const wxPoint& pos,
53 const wxSize& size,
54 const wxArrayString& choices,
55 long style,
56 const wxValidator& validator,
57 const wxString& name)
58 {
59 wxCArrayString chs(choices);
60
61 return Create(parent, id, pos, size, chs.GetCount(), chs.GetStrings(),
62 style, validator, name);
63 }
64
65 #if TARGET_API_MAC_OSX
66 static pascal void DataBrowserItemNotificationProc(ControlRef browser, DataBrowserItemID itemID,
67 DataBrowserItemNotification message, DataBrowserItemDataRef itemData)
68 #else
69 static pascal void DataBrowserItemNotificationProc(ControlRef browser, DataBrowserItemID itemID,
70 DataBrowserItemNotification message)
71 #endif
72 {
73 long ref = GetControlReference( browser ) ;
74 if ( ref )
75 {
76 wxListBox* list = wxDynamicCast( (wxObject*) ref , wxListBox ) ;
77 for ( size_t i = 0 ; i < list->m_idArray.GetCount() ; ++i )
78 if ( list->m_idArray[i] == (long) itemID )
79 {
80 bool trigger = false ;
81 wxCommandEvent event(
82 wxEVT_COMMAND_LISTBOX_SELECTED, list->GetId() );
83 switch( message )
84 {
85 case kDataBrowserItemDeselected :
86 if ( list->HasMultipleSelection() )
87 trigger = true ;
88 break ;
89 case kDataBrowserItemSelected :
90 trigger = true ;
91 break ;
92 case kDataBrowserItemDoubleClicked :
93 event.SetEventType(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED) ;
94 trigger = true ;
95 break ;
96 default :
97 break ;
98 }
99 if ( trigger )
100 {
101 event.SetEventObject( list );
102 if ( list->HasClientObjectData() )
103 event.SetClientObject( list->GetClientObject(i) );
104 else if ( list->HasClientUntypedData() )
105 event.SetClientData( list->GetClientData(i) );
106 event.SetString( list->GetString(i) );
107 event.SetInt(i) ;
108 event.SetExtraLong( list->HasMultipleSelection() ? message == kDataBrowserItemSelected : TRUE );
109 wxPostEvent( list->GetEventHandler() , event ) ;
110 // direct notification is not always having the listbox GetSelection() having in synch with event
111 // list->GetEventHandler()->ProcessEvent(event) ;
112 }
113 break ;
114 }
115 }
116 }
117
118
119 static pascal OSStatus ListBoxGetSetItemData(ControlRef browser,
120 DataBrowserItemID itemID, DataBrowserPropertyID property,
121 DataBrowserItemDataRef itemData, Boolean changeValue)
122 {
123 OSStatus err = errDataBrowserPropertyNotSupported;
124
125 if ( ! changeValue )
126 {
127 switch (property)
128 {
129
130 case kTextColumnId:
131 {
132 long ref = GetControlReference( browser ) ;
133 if ( ref )
134 {
135 wxListBox* list = wxDynamicCast( (wxObject*) ref , wxListBox ) ;
136 for ( size_t i = 0 ; i < list->m_idArray.GetCount() ; ++i )
137 if ( list->m_idArray[i] == (long) itemID )
138 {
139 wxMacCFStringHolder cf( list->GetString(i) , list->GetFont().GetEncoding() ) ;
140 verify_noerr( ::SetDataBrowserItemDataText( itemData , cf ) ) ;
141 err = noErr ;
142 break ;
143 }
144 }
145 }
146 break;
147
148 default:
149
150 break;
151 }
152 }
153
154 return err;
155 }
156 bool wxListBox::Create(wxWindow *parent, wxWindowID id,
157 const wxPoint& pos,
158 const wxSize& size,
159 int n, const wxString choices[],
160 long style,
161 const wxValidator& validator,
162 const wxString& name)
163 {
164 m_macIsUserPane = FALSE ;
165
166 wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED),
167 _T("only one of listbox selection modes can be specified") );
168
169 if ( !wxListBoxBase::Create(parent, id, pos, size, style & ~(wxHSCROLL|wxVSCROLL), validator, name) )
170 return false;
171
172 m_noItems = 0 ; // this will be increased by our append command
173 m_selected = 0;
174 m_nextId = 1 ;
175
176
177 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
178 ControlRef browser ;
179
180 verify_noerr( ::CreateDataBrowserControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, kDataBrowserListView , (ControlRef *)&m_macControl ) );
181 browser = (ControlRef) m_macControl ;
182
183 DataBrowserSelectionFlags options = kDataBrowserDragSelect ;
184 if ( style & wxLB_MULTIPLE )
185 {
186 options += kDataBrowserAlwaysExtendSelection + kDataBrowserCmdTogglesSelection ;
187 }
188 else if ( style & wxLB_EXTENDED )
189 {
190 // default behaviour
191 }
192 else
193 {
194 options += kDataBrowserSelectOnlyOne ;
195 }
196 verify_noerr(SetDataBrowserSelectionFlags (browser, options ) );
197
198 DataBrowserListViewColumnDesc columnDesc ;
199 columnDesc.headerBtnDesc.titleOffset = 0;
200 columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
201
202 columnDesc.headerBtnDesc.btnFontStyle.flags =
203 kControlUseFontMask | kControlUseJustMask;
204
205 columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlNoContent;
206 columnDesc.propertyDesc.propertyType = kDataBrowserTextType;
207 columnDesc.headerBtnDesc.btnFontStyle.just = teFlushDefault;
208 columnDesc.headerBtnDesc.minimumWidth = 0;
209 columnDesc.headerBtnDesc.maximumWidth = 10000;
210
211 columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
212 columnDesc.headerBtnDesc.btnFontStyle.style = normal;
213 columnDesc.headerBtnDesc.titleString = NULL ; // CFSTR( "" );
214
215 columnDesc.propertyDesc.propertyID = kTextColumnId;
216 columnDesc.propertyDesc.propertyType = kDataBrowserTextType;
217 columnDesc.propertyDesc.propertyFlags =
218 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
219 kDataBrowserListViewTypeSelectColumn |
220 #endif
221 kDataBrowserTableViewSelectionColumn ;
222
223
224 verify_noerr(::AddDataBrowserListViewColumn(browser, &columnDesc, kDataBrowserListViewAppendColumn) ) ;
225 verify_noerr(::AutoSizeDataBrowserListViewColumns( browser ) ) ;
226 verify_noerr(::SetDataBrowserHasScrollBars( browser , false , true ) ) ;
227 verify_noerr(::SetDataBrowserTableViewHiliteStyle( browser, kDataBrowserTableViewFillHilite ) ) ;
228 verify_noerr(::SetDataBrowserListViewHeaderBtnHeight( browser , 0 ) ) ;
229 DataBrowserCallbacks callbacks ;
230
231 callbacks.version = kDataBrowserLatestCallbacks;
232
233 InitDataBrowserCallbacks(&callbacks);
234
235 callbacks.u.v1.itemDataCallback =
236 NewDataBrowserItemDataUPP(ListBoxGetSetItemData);
237
238 callbacks.u.v1.itemNotificationCallback =
239 #if TARGET_API_MAC_OSX
240 (DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc) ;
241 #else
242 NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc) ;
243 #endif
244 SetDataBrowserCallbacks(browser, &callbacks);
245
246 MacPostControlCreate(pos,size) ;
247
248 for ( int i = 0 ; i < n ; i++ )
249 {
250 Append( choices[i] ) ;
251 }
252
253 SetBestSize(size); // Needed because it is a wxControlWithItems
254
255 return TRUE;
256 }
257
258 wxListBox::~wxListBox()
259 {
260 SetControlReference( (ControlRef) m_macControl , NULL ) ;
261 FreeData() ;
262 // avoid access during destruction
263 if ( m_macList )
264 {
265 m_macList = NULL ;
266 }
267 }
268
269 void wxListBox::FreeData()
270 {
271 #if wxUSE_OWNER_DRAWN
272 if ( m_windowStyle & wxLB_OWNERDRAW )
273 {
274 size_t uiCount = m_aItems.Count();
275 while ( uiCount-- != 0 ) {
276 delete m_aItems[uiCount];
277 m_aItems[uiCount] = NULL;
278 }
279
280 m_aItems.Clear();
281 }
282 else
283 #endif // wxUSE_OWNER_DRAWN
284 if ( HasClientObjectData() )
285 {
286 for ( size_t n = 0; n < (size_t)m_noItems; n++ )
287 {
288 delete GetClientObject(n);
289 }
290 }
291 }
292
293 void wxListBox::DoSetSize(int x, int y,
294 int width, int height,
295 int sizeFlags )
296 {
297 wxControl::DoSetSize( x , y , width , height , sizeFlags ) ;
298 }
299
300 void wxListBox::DoSetFirstItem(int N)
301 {
302 MacScrollTo( N ) ;
303 }
304
305 void wxListBox::Delete(int N)
306 {
307 wxCHECK_RET( N >= 0 && N < m_noItems,
308 wxT("invalid index in wxListBox::Delete") );
309
310 #if wxUSE_OWNER_DRAWN
311 delete m_aItems[N];
312 m_aItems.RemoveAt(N);
313 #else // !wxUSE_OWNER_DRAWN
314 if ( HasClientObjectData() )
315 {
316 delete GetClientObject(N);
317 }
318 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
319 m_stringArray.RemoveAt( N ) ;
320 m_dataArray.RemoveAt( N ) ;
321 m_noItems --;
322
323 MacDelete( N ) ;
324 }
325
326 int wxListBox::DoAppend(const wxString& item)
327 {
328 int index = m_noItems ;
329 m_stringArray.Add( item ) ;
330 m_dataArray.Add( NULL );
331 m_noItems ++;
332 DoSetItemClientData( index , NULL ) ;
333 MacAppend( item ) ;
334
335 return index ;
336 }
337
338 void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData)
339 {
340 Clear() ;
341 int n = choices.GetCount();
342
343 for( int i = 0 ; i < n ; ++i )
344 {
345 if ( clientData )
346 {
347 #if wxUSE_OWNER_DRAWN
348 wxASSERT_MSG(clientData[i] == NULL,
349 wxT("Can't use client data with owner-drawn listboxes"));
350 #else // !wxUSE_OWNER_DRAWN
351 Append( choices[i] , clientData[i] ) ;
352 #endif
353 }
354 else
355 Append( choices[i] ) ;
356 }
357
358 #if wxUSE_OWNER_DRAWN
359 if ( m_windowStyle & wxLB_OWNERDRAW ) {
360 // first delete old items
361 size_t ui = m_aItems.Count();
362 while ( ui-- != 0 ) {
363 delete m_aItems[ui];
364 m_aItems[ui] = NULL;
365 }
366 m_aItems.Empty();
367
368 // then create new ones
369 for ( ui = 0; ui < (size_t)m_noItems; ui++ ) {
370 wxOwnerDrawn *pNewItem = CreateItem(ui);
371 pNewItem->SetName(choices[ui]);
372 m_aItems.Add(pNewItem);
373 }
374 }
375 #endif // wxUSE_OWNER_DRAWN
376 }
377
378 int wxListBox::FindString(const wxString& s) const
379 {
380
381 if ( s.Right(1) == wxT("*") )
382 {
383 wxString search = s.Left( s.Length() - 1 ) ;
384 int len = search.Length() ;
385 Str255 s1 , s2 ;
386 wxMacStringToPascal( search , s2 ) ;
387
388 for ( int i = 0 ; i < m_noItems ; ++ i )
389 {
390 wxMacStringToPascal( m_stringArray[i].Left( len ) , s1 ) ;
391
392 if ( EqualString( s1 , s2 , false , false ) )
393 return i ;
394 }
395 if ( s.Left(1) == wxT("*") && s.Length() > 1 )
396 {
397 wxString st = s ;
398 st.MakeLower() ;
399 for ( int i = 0 ; i < m_noItems ; ++i )
400 {
401 if ( GetString(i).Lower().Matches(st) )
402 return i ;
403 }
404 }
405
406 }
407 else
408 {
409 Str255 s1 , s2 ;
410
411 wxMacStringToPascal( s , s2 ) ;
412
413 for ( int i = 0 ; i < m_noItems ; ++ i )
414 {
415 wxMacStringToPascal( m_stringArray[i] , s1 ) ;
416
417 if ( EqualString( s1 , s2 , false , false ) )
418 return i ;
419 }
420 }
421 return -1;
422 }
423
424 void wxListBox::Clear()
425 {
426 FreeData();
427 m_noItems = 0;
428 m_stringArray.Empty() ;
429 m_dataArray.Empty() ;
430 MacClear() ;
431 }
432
433 void wxListBox::SetSelection(int N, bool select)
434 {
435 wxCHECK_RET( N >= 0 && N < m_noItems,
436 wxT("invalid index in wxListBox::SetSelection") );
437 MacSetSelection( N , select ) ;
438 GetSelections( m_selectionPreImage ) ;
439 }
440
441 bool wxListBox::IsSelected(int N) const
442 {
443 wxCHECK_MSG( N >= 0 && N < m_noItems, FALSE,
444 wxT("invalid index in wxListBox::Selected") );
445
446 return MacIsSelected( N ) ;
447 }
448
449 void *wxListBox::DoGetItemClientData(int N) const
450 {
451 wxCHECK_MSG( N >= 0 && N < m_noItems, NULL,
452 wxT("invalid index in wxListBox::GetClientData"));
453
454 return (void *)m_dataArray[N];
455 }
456
457 wxClientData *wxListBox::DoGetItemClientObject(int N) const
458 {
459 return (wxClientData *) DoGetItemClientData( N ) ;
460 }
461
462 void wxListBox::DoSetItemClientData(int N, void *Client_data)
463 {
464 wxCHECK_RET( N >= 0 && N < m_noItems,
465 wxT("invalid index in wxListBox::SetClientData") );
466
467 #if wxUSE_OWNER_DRAWN
468 if ( m_windowStyle & wxLB_OWNERDRAW )
469 {
470 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
471 // in OnMeasure/OnDraw.
472 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
473 }
474 #endif // wxUSE_OWNER_DRAWN
475 wxASSERT_MSG( m_dataArray.GetCount() >= (size_t) N , wxT("invalid client_data array") ) ;
476
477 if ( m_dataArray.GetCount() > (size_t) N )
478 {
479 m_dataArray[N] = (char*) Client_data ;
480 }
481 else
482 {
483 m_dataArray.Add( (char*) Client_data ) ;
484 }
485 }
486
487 void wxListBox::DoSetItemClientObject(int n, wxClientData* clientData)
488 {
489 DoSetItemClientData(n, clientData);
490 }
491
492 // Return number of selections and an array of selected integers
493 int wxListBox::GetSelections(wxArrayInt& aSelections) const
494 {
495 return MacGetSelections( aSelections ) ;
496 }
497
498 // Get single selection, for single choice list items
499 int wxListBox::GetSelection() const
500 {
501 return MacGetSelection() ;
502 }
503
504 // Find string for position
505 wxString wxListBox::GetString(int N) const
506 {
507 return m_stringArray[N] ;
508 }
509
510 void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
511 {
512 wxCHECK_RET( pos >= 0 && pos <= m_noItems,
513 wxT("invalid index in wxListBox::InsertItems") );
514
515 int nItems = items.GetCount();
516
517 for ( int i = 0 ; i < nItems ; i++ )
518 {
519 m_stringArray.Insert( items[i] , pos + i ) ;
520 m_dataArray.Insert( NULL , pos + i ) ;
521 MacInsert( pos + i , items[i] ) ;
522 }
523
524 m_noItems += nItems;
525 }
526
527 void wxListBox::SetString(int N, const wxString& s)
528 {
529 m_stringArray[N] = s ;
530 MacSet( N , s ) ;
531 }
532
533 wxSize wxListBox::DoGetBestSize() const
534 {
535 int lbWidth = 100; // some defaults
536 int lbHeight = 110;
537 int wLine;
538
539 {
540 wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetTopLevelWindowRef() ) ) ;
541
542 if ( m_font.Ok() )
543 {
544 ::TextFont( m_font.MacGetFontNum() ) ;
545 ::TextSize( m_font.MacGetFontSize() ) ;
546 ::TextFace( m_font.MacGetFontStyle() ) ;
547 }
548 else
549 {
550 ::TextFont( kFontIDMonaco ) ;
551 ::TextSize( 9 );
552 ::TextFace( 0 ) ;
553 }
554
555 // Find the widest line
556 for(int i = 0; i < GetCount(); i++) {
557 wxString str(GetString(i));
558 #if wxUSE_UNICODE
559 Point bounds={0,0} ;
560 SInt16 baseline ;
561 ::GetThemeTextDimensions( wxMacCFStringHolder( str , m_font.GetEncoding() ) ,
562 kThemeCurrentPortFont,
563 kThemeStateActive,
564 false,
565 &bounds,
566 &baseline );
567 wLine = bounds.h ;
568 #else
569 wLine = ::TextWidth( str.c_str() , 0 , str.Length() ) ;
570 #endif
571 lbWidth = wxMax(lbWidth, wLine);
572 }
573
574 // Add room for the scrollbar
575 lbWidth += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
576
577 // And just a bit more
578 int cy = 12 ;
579 int cx = ::TextWidth( "X" , 0 , 1 ) ;
580 lbWidth += cx ;
581
582 // don't make the listbox too tall (limit height to around 10 items) but don't
583 // make it too small neither
584 lbHeight = (cy+4) * wxMin(wxMax(GetCount(), 3), 10);
585 }
586
587 return wxSize(lbWidth, lbHeight);
588 }
589
590 int wxListBox::GetCount() const
591 {
592 return m_noItems;
593 }
594
595 void wxListBox::Refresh(bool eraseBack, const wxRect *rect)
596 {
597 wxControl::Refresh( eraseBack , rect ) ;
598 // MacRedrawControl() ;
599 }
600
601 #if wxUSE_OWNER_DRAWN
602
603 class wxListBoxItem : public wxOwnerDrawn
604 {
605 public:
606 wxListBoxItem(const wxString& str = "");
607 };
608
609 wxListBoxItem::wxListBoxItem(const wxString& str) : wxOwnerDrawn(str, FALSE)
610 {
611 // no bitmaps/checkmarks
612 SetMarginWidth(0);
613 }
614
615 wxOwnerDrawn *wxListBox::CreateItem(size_t n)
616 {
617 return new wxListBoxItem();
618 }
619
620 #endif //USE_OWNER_DRAWN
621
622 // ============================================================================
623 // list box control implementation
624 // ============================================================================
625
626 void wxListBox::MacDelete( int N )
627 {
628 UInt32 id = m_idArray[N] ;
629 verify_noerr(::RemoveDataBrowserItems((ControlRef) m_macControl , kDataBrowserNoItem , 1 , (UInt32*) &id , kDataBrowserItemNoProperty ) ) ;
630 m_idArray.RemoveAt( N ) ;
631 }
632
633 void wxListBox::MacInsert( int n , const wxString& text)
634 {
635 verify_noerr(::AddDataBrowserItems( (ControlRef) m_macControl , kDataBrowserNoItem , 1 , (UInt32*) &m_nextId , kDataBrowserItemNoProperty ) ) ;
636 m_idArray.Insert( m_nextId , n ) ;
637 ++m_nextId ;
638 }
639
640 void wxListBox::MacAppend( const wxString& text)
641 {
642 verify_noerr(::AddDataBrowserItems( (ControlRef) m_macControl , kDataBrowserNoItem , 1 , (UInt32*) &m_nextId , kDataBrowserItemNoProperty ) ) ;
643 m_idArray.Add( m_nextId ) ;
644 ++m_nextId ;
645 }
646
647 void wxListBox::MacClear()
648 {
649 verify_noerr(::RemoveDataBrowserItems((ControlRef) m_macControl , kDataBrowserNoItem , 0 , NULL , kDataBrowserItemNoProperty ) ) ;
650 m_idArray.Empty() ;
651 }
652
653 void wxListBox::MacSetSelection( int n , bool select )
654 {
655 UInt32 id = m_idArray[n] ;
656 if ( !(GetWindowStyle() & (wxLB_MULTIPLE|wxLB_EXTENDED) ) )
657 {
658 int n = MacGetSelection() ;
659 if ( n >= 0 )
660 {
661 UInt32 idOld = m_idArray[n] ;
662 SetDataBrowserSelectedItems((ControlRef) m_macControl , 1 , & idOld , kDataBrowserItemsRemove ) ;
663 }
664 }
665 if ( ::IsDataBrowserItemSelected( (ControlRef) m_macControl , id ) != select )
666 {
667 verify_noerr(::SetDataBrowserSelectedItems((ControlRef) m_macControl , 1 , & id , kDataBrowserItemsToggle ) ) ;
668 }
669 MacScrollTo( n ) ;
670 }
671
672 bool wxListBox::MacIsSelected( int n ) const
673 {
674 return ::IsDataBrowserItemSelected( (ControlRef) m_macControl , m_idArray[n] ) ;
675 }
676
677 int wxListBox::MacGetSelection() const
678 {
679 for ( size_t i = 0 ; i < m_idArray.GetCount() ; ++i )
680 {
681 if ( ::IsDataBrowserItemSelected((ControlRef) m_macControl , m_idArray[i] ) )
682 {
683 return i ;
684 }
685 }
686 return -1 ;
687 }
688
689 int wxListBox::MacGetSelections( wxArrayInt& aSelections ) const
690 {
691 int no_sel = 0 ;
692
693 aSelections.Empty();
694 for ( size_t i = 0 ; i < m_idArray.GetCount() ; ++i )
695 {
696 if ( ::IsDataBrowserItemSelected((ControlRef) m_macControl , m_idArray[i] ) )
697 {
698 aSelections.Add( i ) ;
699 no_sel++ ;
700 }
701 }
702 return no_sel ;
703 }
704
705 void wxListBox::MacSet( int n , const wxString& text )
706 {
707 // as we don't store the strings we only have to issue a redraw
708 UInt32 id = m_idArray[n] ;
709 verify_noerr( ::UpdateDataBrowserItems( (ControlRef) m_macControl , kDataBrowserNoItem , 1 , &id , kDataBrowserItemNoProperty , kDataBrowserItemNoProperty ) ) ;
710 }
711
712 void wxListBox::MacScrollTo( int n )
713 {
714 UInt32 id = m_idArray[n] ;
715 verify_noerr( ::RevealDataBrowserItem((ControlRef) m_macControl , id , kTextColumnId , kDataBrowserRevealWithoutSelecting ) ) ;
716 }
717
718 #if !TARGET_API_MAC_OSX
719 void wxListBox::OnSize( wxSizeEvent &event)
720 {
721 }
722 #endif
723
724 void wxListBox::MacSetRedraw( bool doDraw )
725 {
726 // nothing to do in compositing mode
727 }
728
729 void wxListBox::MacDoClick()
730 {/*
731 wxArrayInt aSelections;
732 int n ;
733 size_t count = GetSelections(aSelections);
734
735 if ( count == m_selectionPreImage.GetCount() )
736 {
737 bool hasChanged = false ;
738 for ( size_t i = 0 ; i < count ; ++i )
739 {
740 if ( aSelections[i] != m_selectionPreImage[i] )
741 {
742 hasChanged = true ;
743 break ;
744 }
745 }
746 if ( !hasChanged )
747 {
748 return ;
749 }
750 }
751
752 m_selectionPreImage = aSelections;
753
754 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId);
755 event.SetEventObject( this );
756
757 if ( count > 0 )
758 {
759 n = aSelections[0];
760 if ( HasClientObjectData() )
761 event.SetClientObject( GetClientObject(n) );
762 else if ( HasClientUntypedData() )
763 event.SetClientData( GetClientData(n) );
764 event.SetString( GetString(n) );
765 }
766 else
767 {
768 n = -1;
769 }
770
771 event.m_commandInt = n;
772
773 GetEventHandler()->ProcessEvent(event);
774 */
775 }
776
777 void wxListBox::MacDoDoubleClick()
778 {
779 /*
780 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, m_windowId);
781 event.SetEventObject( this );
782 GetEventHandler()->ProcessEvent(event) ;
783 */
784 }
785
786 #if !TARGET_API_MAC_OSX
787
788 void wxListBox::OnChar(wxKeyEvent& event)
789 {
790 // todo trigger proper events here
791 event.Skip() ;
792 return ;
793
794 if ( event.GetKeyCode() == WXK_RETURN || event.GetKeyCode() == WXK_NUMPAD_ENTER)
795 {
796 wxWindow* parent = GetParent() ;
797 while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL )
798 parent = parent->GetParent() ;
799
800 if ( parent && parent->GetDefaultItem() )
801 {
802 wxButton *def = wxDynamicCast(parent->GetDefaultItem(),
803 wxButton);
804 if ( def && def->IsEnabled() )
805 {
806 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
807 event.SetEventObject(def);
808 def->Command(event);
809 return ;
810 }
811 }
812 event.Skip() ;
813 }
814 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
815 else if (event.GetKeyCode() == WXK_ESCAPE || (event.GetKeyCode() == '.' && event.MetaDown() ) )
816 {
817 // FIXME: look in ancestors, not just parent.
818 wxWindow* win = GetParent()->FindWindow( wxID_CANCEL ) ;
819 if (win)
820 {
821 wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
822 new_event.SetEventObject( win );
823 win->GetEventHandler()->ProcessEvent( new_event );
824 }
825 }
826 else if ( event.GetKeyCode() == WXK_TAB )
827 {
828 wxNavigationKeyEvent new_event;
829 new_event.SetEventObject( this );
830 new_event.SetDirection( !event.ShiftDown() );
831 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
832 new_event.SetWindowChange( event.ControlDown() );
833 new_event.SetCurrentFocus( this );
834 if ( !GetEventHandler()->ProcessEvent( new_event ) )
835 event.Skip() ;
836 }
837 else if ( event.GetKeyCode() == WXK_DOWN || event.GetKeyCode() == WXK_UP )
838 {
839 // perform the default key handling first
840 wxControl::OnKeyDown( event ) ;
841
842 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId);
843 event.SetEventObject( this );
844
845 wxArrayInt aSelections;
846 int n, count = GetSelections(aSelections);
847 if ( count > 0 )
848 {
849 n = aSelections[0];
850 if ( HasClientObjectData() )
851 event.SetClientObject( GetClientObject(n) );
852 else if ( HasClientUntypedData() )
853 event.SetClientData( GetClientData(n) );
854 event.SetString( GetString(n) );
855 }
856 else
857 {
858 n = -1;
859 }
860
861 event.m_commandInt = n;
862
863 GetEventHandler()->ProcessEvent(event);
864 }
865 else
866 {
867 if ( event.GetTimestamp() > m_lastTypeIn + 60 )
868 {
869 m_typeIn = wxEmptyString ;
870 }
871 m_lastTypeIn = event.GetTimestamp() ;
872 m_typeIn += (char) event.GetKeyCode() ;
873 int line = FindString(wxT("*")+m_typeIn+wxT("*")) ;
874 if ( line >= 0 )
875 {
876 if ( GetSelection() != line )
877 {
878 SetSelection(line) ;
879 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId);
880 event.SetEventObject( this );
881
882 if ( HasClientObjectData() )
883 event.SetClientObject( GetClientObject( line ) );
884 else if ( HasClientUntypedData() )
885 event.SetClientData( GetClientData(line) );
886 event.SetString( GetString(line) );
887
888 event.m_commandInt = line ;
889
890 GetEventHandler()->ProcessEvent(event);
891 }
892 }
893 }
894 }
895
896 #endif
897